OPERATING SYSTEM ---------------- All FULL JDK VERSION ---------------- All Java 6 PROBLEM DESCRIPTION ------------------- The JavaDoc of the add(URI uri, HttpCookie cookie) method of java.net.CookieStore indicates that null is an acceptable value for the URI parameter: "uri - the uri this cookie associated with. if null, this cookie will not be associated with an URI" http://java.sun.com/javase/6/docs/api/java/net/CookieStore.html#add(java.net.URI,%20java.net.HttpCookie However, calling this method with null URI is causes a NullPointerException: java.lang.NullPointerException at sun.net.www.protocol.http.InMemoryCookieStore.getEffectiveURI(Unknown Source) at sun.net.www.protocol.http.InMemoryCookieStore.add(Unknown Source) at Main.main(Main.java:44) REPRODUCTION INSTRUCTIONS ------------------------- Compile and run the testcase provided. TESTCASE -------- import java.net.CookieManager; import java.net.CookieStore; import java.net.HttpCookie; public class CookieTest { public static void main(String[] args) { //get a cookie store implementation and add a cookie to the store with null URI CookieStore cookieStore = (new CookieManager()).getCookieStore(); cookieStore.add(null, new HttpCookie("MY_COOKIE", "MY_COOKIE_VALUE")); } }
|