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

URLConnection::getHeaderFields returns result inconsistent with getHeaderField/Key for FileURLConnection, FtpURLConnection

XMLWordPrintable

    • b25
    • Verified

      Consider the following code with the specs quoted

              URLConnection c = new URL("file:/usr").openConnection();
              c.connect();

              System.out.println("c = " + c);
              // "The Map keys are Strings that represent the response-header field names"
              System.out.println(c.getHeaderFields().keySet());

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

              // "It returns null if there are fewer than n+1 fields."
              System.out.println(c.getHeaderField(0));

      The output would be:

      c = sun.net.www.protocol.file.FileURLConnection:file:/usr
      []
      content-type
      text/plain

      ::getHeaderFields indicates that there are zero header fields while getHeaderField/Key(index) say the opposite

      FtpURLConnection seem to be affected as well as FileURLConnection

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

              Created:
              Updated:
              Resolved: