RFR: 8268960: com/sun/net/httpserver/Headers.java: Ensure mutators normalize keys and disallow null for keys and values [v3]

Daniel Fuchs dfuchs at openjdk.java.net
Thu Jun 24 15:20:30 UTC 2021


On Wed, 23 Jun 2021 18:02:02 GMT, Julia Boes <jboes at openjdk.org> wrote:

>> `com.sun.net.httpserver.Headers` normalizes its keys to adhere to the following format: First character uppercase, all other characters lowercase, for example `"foo" -> "Foo"`. This behaviour is not consistent across the mutator methods of the class, in particular `putAll()` and `replaceAll()` do not apply normalization.
>> 
>> The suggested fix is to update the implementation of `putAll()` and to add an implementation of of the java.util.Map default method `replaceAll()`. While here, we can improve `equals()` by adding a type check and add a `toString()` implementation.
>> 
>> Additionally,  the Headers class is updated to disallow null values for keys and values.
>
> Julia Boes has updated the pull request incrementally with one additional commit since the last revision:
> 
>   confirm HttpExchange::sendResponseHeaders fails if key/value null

Marked as reviewed by dfuchs (Reviewer).

src/jdk.httpserver/share/classes/com/sun/net/httpserver/Headers.java line 115:

> 113:     @Override
> 114:     public boolean containsKey(Object key) {
> 115:         Objects.requireNonNull(key);

I haven't looked at the CSR yet - but maybe the fact that the get and contains* method can now throw NPE - in conformance to the Map interface specification for maps that do not allow null keys or null values, should be explicitly mentioned - in particular in the release note - as this will probably be the less expected behavior change.

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

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


More information about the net-dev mailing list