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

HttpURLConnection.getHeaderFields() throws IllegalArgumentException: Empty cookie header string

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 8
    • Fix Version/s: 8
    • Component/s: core-libs
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      b98
    • CPU:
      generic
    • OS:
      generic
    • Verification:
      Verified

      Description

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

      Exception in thread "main" java.lang.IllegalArgumentException: Empty cookie header string
      at java.net.HttpCookie.parseInternal(HttpCookie.java:828)
      at java.net.HttpCookie.parse(HttpCookie.java:204)
      at java.net.HttpCookie.access$100(HttpCookie.java:58)
      at java.net.HttpCookie$12.parse(HttpCookie.java:979)
      at sun.net.www.protocol.http.HttpURLConnection.filterHeaderField(HttpURLConnection.java:2632)
      at sun.net.www.protocol.http.HttpURLConnection.getFilteredHeaderFields(HttpURLConnection.java:2669)
      at sun.net.www.protocol.http.HttpURLConnection.getHeaderFields(HttpURLConnection.java:2713)
      at emptycookieheaderstringtest.EmptyCookieHeaderStringTest.main(EmptyCookieHeaderStringTest.java:17)

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

      public class EmptyCookieHeaderStringTest {
          public static void main(String[] args) throws IOException {
              CookieHandler.setDefault(new TestCookieHandler());
              URL url = new URL("http://www.walmart.com/msharbor/");
              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) {
          }
      }

      The problem is the root cause for https://javafx-jira.kenai.com/browse/RT-30052 .

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                jzavgren John Zavgren (Inactive)
                Reporter:
                vbaranov Vasiliy Baranov (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: