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

j.net.URLConnection::getHeaderFieldKey(int) behavior does not reliably conform to its specification

    XMLWordPrintable

Details

    • b25

    Description

      The following happens with HttpURLConnection

      Consider the following code with the specs quoted

              URLConnection urlConnection = new URL("http://oracle.com").openConnection();

              // "It returns null if there are fewer than n+1 fields.
              // This method can be used in conjunction with the getHeaderFieldKey method
              // to iterate through all the headers in the message."
              System.out.println(urlConnection.getHeaderField(0));

              // Returns the key for the nth header field.
              // It returns null if there are fewer than n+1 fields.
              System.out.println(urlConnection.getHeaderFieldKey(0));

              Map<String, List<String>> headerFields = urlConnection.getHeaderFields();
              System.out.println("headerFields = " + headerFields);

      The output would be:

      HTTP/1.0 301 Moved Permanently
      null
      headerFields = {null=[HTTP/1.0 301 Moved Permanently], Connection=[close], Content-Length=[0], Location=[https://www.oracle.com/]}


      getHeaderField(int) could not be used in conjunction with getHeaderFieldKey(int) and behavior of the latter doesn't conform to its specification

      Attachments

        Issue Links

          Activity

            People

              michaelm Michael McMahon
              dbessono Dmitry Bessonov
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: