FULL PRODUCT VERSION :
1.7.0_21
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.2.9200]
Windows 8 64 bit
EXTRA RELEVANT SYSTEM CONFIGURATION :
Laptop connected to internet over a home wifi.
A DESCRIPTION OF THE PROBLEM :
The cookie store remains empty it does not have cookies. This is observed only with the version of java 1.7.0_21. Maybe it fails to hold cookies which are marked as httponly, though I'm not sure.
REGRESSION. Last worked in version 8u92
ADDITIONAL REGRESSION INFORMATION:
1.7.0_21.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Please compile and run the POC code with java 1.7.0_21. It is a simple program to fetch cookies from a website. However it would turn out that cookie store is empty.
The same POC code gives cookies as expected when compiled and run with java 1.8.
/* ************code begins ************************** */
import java.net.CookieHandler;
import java.net.CookieManager;
import java.net.CookiePolicy;
import java.net.CookieStore;
import java.net.HttpCookie;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.List;
public class Main2 {
public static void main(String[] args) throws Exception {
final String USER_AGENT = "Mozilla/5.0";
CookieManager manager = new CookieManager();
manager.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
CookieHandler.setDefault(manager);
URL url = new URL("http://www.angelvestgroup.com/info.php?id=1");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("User-Agent", USER_AGENT);
conn.getContent();
CookieStore cookieJar = manager.getCookieStore();
List<HttpCookie> cookies = cookieJar.get(url.toURI());
if(cookies.isEmpty())
System.out.println("Empty");
for (HttpCookie cookie : cookies) {
System.out.println("CookieHandler retrieved cookie: " + cookie);
}
}
}
/* ************code ends ************************** */
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Output should be the cookie obtained for ex:
CookieHandler retrieved cookie: __cfduid=<some data>
ACTUAL -
The program prints :
Empty
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.net.CookieHandler;
import java.net.CookieManager;
import java.net.CookiePolicy;
import java.net.CookieStore;
import java.net.HttpCookie;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.List;
public class Main2 {
public static void main(String[] args) throws Exception {
final String USER_AGENT = "Mozilla/5.0";
CookieManager manager = new CookieManager();
manager.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
CookieHandler.setDefault(manager);
URL url = new URL("http://www.angelvestgroup.com/info.php?id=1");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("User-Agent", USER_AGENT);
conn.getContent();
CookieStore cookieJar = manager.getCookieStore();
List<HttpCookie> cookies = cookieJar.get(url.toURI());
if(cookies.isEmpty())
System.out.println("Empty");
for (HttpCookie cookie : cookies) {
System.out.println("CookieHandler retrieved cookie: " + cookie);
}
}
}
---------- END SOURCE ----------