JDK-7129083 : CookieManager does not store cookies if url is read before setting cookie manager
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 6u29
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2012-01-11
  • Updated: 2014-11-19
  • Resolved: 2012-08-20
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6 JDK 7 JDK 8
6u32Fixed 7u4Fixed 8 b23Fixed
Description
SHORT SUMMARY: No cookies stored if cookieManager installed after caching of 
HttpClient

INDICATORS: Subsequent requests to the same URL resource may fail to cache 
cookies if a cookiemanager is installed after first request is made.

When caching is enabled, the JRE maintains
@ a cache of httpClients objects for re-use (for identical URLs)
@ .
@ When the httpClient object is taken from the cache, no checks are made to 
see
@ if a CookieManager has been installed since first constructed. I'm 
currently
@ testing with a new fix verification binary and once I have review from Dev
@ engineer, I'll make the binary available for internal testing.
@ .
@ One workaround is to set the following java system property flag to false : 
"
@ -Dhttp.keepAlive=false"


COUNTER INDICATORS:
TRIGGERS: Multiple connections to the same URL resource while installing a 
cookieManager after the 1st connection.

KNOWN WORKAROUND: Dhttp.keepAlive=false
PRESENT SINCE: N/A
HOW TO VERIFY: Testcase will be made available
NOTES FOR SE: N/A
REGRESSION: No.

Comments
EVALUATION JDK8 changeset: Changeset: e8a143213c65 Author: chegar Date: 2012-01-16 18:05 +0000 URL: http://hg.openjdk.java.net/jdk8/tl/jdk/rev/e8a143213c65 7129083: CookieManager does not store cookies if url is read before setting cookie manager Reviewed-by: michaelm ! src/share/classes/sun/net/www/http/HttpClient.java ! src/share/classes/sun/net/www/protocol/http/HttpURLConnection.java ! src/share/classes/sun/net/www/protocol/https/HttpsClient.java + test/sun/net/www/http/HttpClient/CookieHttpClientTest.java + test/sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/CookieHttpsClientTest.java
16-01-2012

EVALUATION The system-wide CookieHandler is read and stored in the sun.net.www.http(s) HttpClient/HttpsClient instance. Since this HttpClient/HttpsClient instance is cached and reused (where possible) as part of the persistent/keep-alive connection implementation, it will not reflect any changes made to the default system-wide CookieHandler after it is created. It is unspecified what effect changing the system-wide CookieHandler will have on the HTTP Client, but is seems reasonable that the two parts of the HTTP Client implementation, HttpURLConnection and HttpClient, should use the same CookieHandler. HttpClient should use the instance specific (most recently retrieved system-wide CookieHandler) from HttpURLConnection.
16-01-2012