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

Daniel Fuchs dfuchs at openjdk.java.net
Mon Mar 22 16:40:42 UTC 2021


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

>> src/jdk.httpserver/share/classes/sun/net/httpserver/UnmodifiableHeaders.java line 34:
>> 
>>> 32: public class UnmodifiableHeaders extends Headers {
>>> 33: 
>>> 34:         private Map<String, List<String>> map;
>> 
>> How about:
>> 
>> private final Headers headers;
>> private final Map<String, List<String>> map;
>> 
>> public UnmodifiableHeaders(Headers headers) {
>>     this.map = Collections.unmodifiableMap(headers);
>>     this.headers = headers;
>> }
>> 
>> Then getFirst simply becomes `return headers.getFirst(key);`
>
> I guess this presumes that no reference to `headers` escapes? Can that be assumed?

Yes - it's private - and that wasn't a problem before - was it? The problem was the put method that still put things into the map - and that will be taken care of if the map is unmodifiable.

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

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


More information about the net-dev mailing list