Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8031028 | 7u80 | Dmeetry Degrave | P3 | Resolved | Fixed | b01 |
JDK-8060947 | 7u79 | Kurchi Subhra Hazra | P3 | Resolved | Fixed | b01 |
JDK-8057418 | 7u76 | Kurchi Subhra Hazra | P3 | Resolved | Fixed | b01 |
JDK-8047612 | 7u72 | Kurchi Subhra Hazra | P3 | Resolved | Fixed | b01 |
JDK-8040859 | 7u71 | Kurchi Subhra Hazra | P3 | Resolved | Fixed | b01 |
JDK-8040339 | 7u66 | Kurchi Subhra Hazra | P3 | Closed | Won't Fix |
Bug Description:
The java.net.CookieHandler does not work with localhost and any host name without a dot. The bug seems in the implementation of java.net.HttpCookie.domainMatch() or the usage in java.netCookiePolicy. ACCEPT_ORIGINAL_SERVER.
Working host names:
MyHost.local
127.0.0.1
any IPv4 address
Not working host names:
MyHost
[::1]
any IPv6 address
We see the problem with Java 6 and 7. It is not a regression.
To run the follow code you need only a local http server which send a cookie. For example a session cookie.
URL url = new URL( "http://localhost/ );
HttpURLConnection urlConnection = (HttpURLConnection)url.openConnection();
urlConnection.connect();
urlConnection.getInputStream();
if (newcookie != null) {
CookieHandler cookieHandler = CookieHandler.getDefault();
if (cookieHandler == null) {
cookieHandler = new java.net.CookieManager();
CookieHandler.setDefault( cookieHandler );
}
try {
cookieHandler.put( urlConnection.getURL().toURI(), urlConnection.getHeaderFields() );
Map<String, List<String>> map = cookieHandler.get( urlConnection.getURL().toURI(), urlConnection.getHeaderFields() );
if (map.containsKey( "Cookie" )) {
List<String> list = map.get( "Cookie" ); // The list is empty for localhost and host names without dot
if (list != null && list.size()>0) {
String element = list.get( 0 );
if (element != null && element.length()>0) {
setCookie(element); // Use for the next request
}
}
}
} catch( URISyntaxException e ) {
e.printStackTrace();
}
}
The java.net.CookieHandler does not work with localhost and any host name without a dot. The bug seems in the implementation of java.net.HttpCookie.domainMatch() or the usage in java.netCookiePolicy. ACCEPT_ORIGINAL_SERVER.
Working host names:
MyHost.local
127.0.0.1
any IPv4 address
Not working host names:
MyHost
[::1]
any IPv6 address
We see the problem with Java 6 and 7. It is not a regression.
To run the follow code you need only a local http server which send a cookie. For example a session cookie.
URL url = new URL( "http://localhost/ );
HttpURLConnection urlConnection = (HttpURLConnection)url.openConnection();
urlConnection.connect();
urlConnection.getInputStream();
if (newcookie != null) {
CookieHandler cookieHandler = CookieHandler.getDefault();
if (cookieHandler == null) {
cookieHandler = new java.net.CookieManager();
CookieHandler.setDefault( cookieHandler );
}
try {
cookieHandler.put( urlConnection.getURL().toURI(), urlConnection.getHeaderFields() );
Map<String, List<String>> map = cookieHandler.get( urlConnection.getURL().toURI(), urlConnection.getHeaderFields() );
if (map.containsKey( "Cookie" )) {
List<String> list = map.get( "Cookie" ); // The list is empty for localhost and host names without dot
if (list != null && list.size()>0) {
String element = list.get( 0 );
if (element != null && element.length()>0) {
setCookie(element); // Use for the next request
}
}
}
} catch( URISyntaxException e ) {
e.printStackTrace();
}
}
- backported by
-
JDK-8031028 CookieHandler does not work with localhost
- Resolved
-
JDK-8040859 CookieHandler does not work with localhost
- Resolved
-
JDK-8047612 CookieHandler does not work with localhost
- Resolved
-
JDK-8057418 CookieHandler does not work with localhost
- Resolved
-
JDK-8060947 CookieHandler does not work with localhost
- Resolved
-
JDK-8040339 CookieHandler does not work with localhost
- Closed
- relates to
-
JDK-8034200 Test java/net/CookieHandler/LocalHostCookie.java fails after fix of JDK-7169142
- Resolved
(1 backported by, 1 relates to)