RFR: 8263506: Make sun.net.httpserver.UnmodifiableHeaders unmodifiable

Daniel Fuchs dfuchs at openjdk.java.net
Mon Mar 22 16:44:38 UTC 2021


On Mon, 22 Mar 2021 16:25:24 GMT, Michael McMahon <michaelm at openjdk.org> wrote:

>> Headers normalizes the key before any get/getFirst, for example Headers line 131:
>> 
>> `public List<String> get(Object key) {
>>             return map.get(normalize((String)key));
>>         }`
>> 
>> I assume we want to maintain this behaviour, but there might be a better way than creating this local Headers?
>
> Actually, I just noticed that the `List<String>`s are still modifiable. The constructor might have to create an intermediate `Map<String,List<String>>` with unmodifiable Lists and then you create an unmodifiable Map from that. 
> 
> As regards the comment above, yes you want to maintain that behavior. Could you normalize the key here and then just return `map.get(key).get(0)` (with suitable null checks)?

Argh. Good catch Michael.  So now we'd also have to reimplement values() and get() to wrap things into unmodifiableList... Or could we get away with providing an immutable snapshot instead of an immutable view?

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

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


More information about the net-dev mailing list