JDK-8160038 : Cookie Store is empty even when cookies are sent in http response
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 7u21
  • Priority: P4
  • Status: Closed
  • Resolution: Cannot Reproduce
  • OS: generic
  • CPU: generic
  • Submitted: 2016-06-20
  • Updated: 2016-06-22
  • Resolved: 2016-06-22
Description
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 ----------


Comments
The test case fails only on JDK 7u21 . It passes on all the later releases. JDK 7u21 - Fail JDK 7u80 - Pass JDK 8u92 - Pass JDK 9 eab122 - Pass Removed the regression label, reduced the priority and closing as cannot reproduce.
22-06-2016