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

HttpURLConnection.getHeaderFields() throws IllegalArgumentException: Illegal cookie name

    Details

    • Subcomponent:
    • Introduced In Version:
      7u4
    • Resolved In Build:
      b22
    • CPU:
      generic
    • OS:
      generic
    • Verification:
      Verified

      Backports

        Description

        If a program installs the default cookie handler, opens an HttpURLConnection to http://www.google.com, and attempts to call HttpURLConnection.getHeaderFields() on that connection, HttpURLConnection.getHeaderFields() unexpectedly throws the following exception:

        Exception in thread "main" java.lang.IllegalArgumentException: Illegal cookie name
        at java.net.HttpCookie.<init>(HttpCookie.java:158)
        at java.net.HttpCookie.parseInternal(HttpCookie.java:964)
        at java.net.HttpCookie.parse(HttpCookie.java:215)
        at java.net.HttpCookie.access$100(HttpCookie.java:58)
        at java.net.HttpCookie$12.parse(HttpCookie.java:1096)
        at sun.net.www.protocol.http.HttpURLConnection.filterHeaderField(HttpURLConnection.java:2605)
        at sun.net.www.protocol.http.HttpURLConnection.getFilteredHeaderFields(HttpURLConnection.java:2642)
        at sun.net.www.protocol.http.HttpURLConnection.getHeaderFields(HttpURLConnection.java:2686)
        at illegalcookienametest.IllegalCookieNameTest.main(IllegalCookieNameTest.java:17)

        To reproduce, compile and run the following program (with -DproxyHost=<proxy> -DproxyPort=<port>, if you are behind a proxy):

        public class IllegalCookieNameTest {
            public static void main(String[] args) throws IOException {
                CookieHandler.setDefault(new TestCookieHandler());
                URL url = new URL("http://www.google.com/");
                HttpURLConnection c = (HttpURLConnection) url.openConnection();
                c.getHeaderFields();
            }
        }

        class TestCookieHandler extends CookieHandler {
            @Override
            public Map<String, List<String>> get(URI uri, Map<String, List<String>> requestHeaders) {
                return new HashMap<String, List<String>>();
            }

            @Override
            public void put(URI uri, Map<String, List<String>> responseHeaders) {
            }
        }

        This is a major problem for JavaFX WebView, see http://javafx-jira.kenai.com/browse/RT-23353

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  michaelm Michael McMahon
                  Reporter:
                  vbaranov Vasiliy Baranov (Inactive)
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  1 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved:
                    Imported:
                    Indexed: