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

Michael McMahon michaelm at openjdk.java.net
Mon Mar 22 15:32:48 UTC 2021


On Tue, 16 Mar 2021 14:19:09 GMT, Julia Boes <jboes at openjdk.org> wrote:

> The fix makes the map in sun.net.httpserver.UnmodifiableHeaders unmodifiable by wrapping it in an unmodifiable view.

Changes requested by michaelm (Reviewer).

src/jdk.httpserver/share/classes/sun/net/httpserver/UnmodifiableHeaders.java line 60:

> 58:             map.forEach((k, v) -> headers.add(k, v.get(0)));
> 59:             return headers.getFirst(key);
> 60:         }

Should be possible to just return a reference to the first String in the map rather than instantiating a new Headers and populating it just for the duration of the call.

src/jdk.httpserver/share/classes/sun/net/httpserver/UnmodifiableHeaders.java line 88:

> 86:         public Set<String> keySet() {
> 87:             return Collections.unmodifiableSet(map.keySet());
> 88:         }

Should be able to just return "map.keySet()" here because map is already unmodifiable

src/jdk.httpserver/share/classes/sun/net/httpserver/UnmodifiableHeaders.java line 98:

> 96:         public Set<Map.Entry<String, List<String>>> entrySet() {
> 97:             return Collections.unmodifiableSet(map.entrySet());
> 98:         }

Same as previous comment.

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

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


More information about the net-dev mailing list