RFR: 8133686: HttpURLConnection.getHeaderFields and URLConnection.getRequestProperties methods return field values in reverse order

Daniel Fuchs dfuchs at openjdk.java.net
Thu Jan 28 17:06:42 UTC 2021


On Thu, 28 Jan 2021 16:42:02 GMT, Evan Whelan <ewhelan at openjdk.org> wrote:

> Hi all,
> 
> Please review this fix for which corrects the order in which field values are returned from the `HttpURLConnection.getHeaderFields` and `URLConnection.getRequestProperties` methods.
> 
> Currently, the implementation of these methods returns the values in reverse. This does not conform with the RFC2616 spec which outlines that the order of these field values should not be changed. 
> 
> Thanks,
> Evan

Changes requested by dfuchs (Reviewer).

src/java.base/share/classes/java/net/URLConnection.java line 1201:

> 1199:      * @implSpec The default implementation of this method should preserve insertion order when
> 1200:      * multiple values are added for a given key. They must be
> 1201:      * returned in the order they were added.

If we are speaking about what the default implementation actually does, then the conditional tense should be removed. And this should probably be an @implNote. 

     * @implNote The default implementation of this method preserves the insertion order when
     * multiple values are added for a given key. The values are returned in the order they 
     * were added.

src/java.base/share/classes/java/net/URLConnection.java line 596:

> 594:      * corresponding values, they must be returned in the order they were added,
> 595:      * preserving the insertion-order.
> 596:      *

Here the `@implSpec` is right because it describes how subclasses should implement the method.
Maybe there should be an additional `@implNote` as well to describe what the default implementation does.

      * @implNote The default implementation of this method returns an empty map always.

The `@implNote` is useful for subclasses to decide whether they should override the default implementation.

-------------

PR: https://git.openjdk.java.net/jdk/pull/2294


More information about the net-dev mailing list