Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6953455

CookieStore.add() cannot handle null URI parameter, contrary to the API specification

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • P4
    • Resolution: Fixed
    • 6, 7u6
    • 8
    • core-libs
    • b10
    • generic, sparc
    • os_x, solaris_2.5.1
    • Verified

    Backports

      Description

        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"));
            }
        }

        Attachments

          Issue Links

            Activity

              People

                khazra Kurchi Subhra Hazra
                dkorbel David Korbel (Inactive)
                Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: