ppkarwasz commented on code in PR #2101:
URL: https://github.com/apache/logging-log4j2/pull/2101#discussion_r1429863496


##########
log4j-core/src/main/java/org/apache/logging/log4j/core/impl/JdkMapAdapterStringMap.java:
##########
@@ -52,6 +52,11 @@ public JdkMapAdapterStringMap() {
 
     public JdkMapAdapterStringMap(final Map<String, String> map) {
         this.map = Objects.requireNonNull(map, "map");
+        try {
+            map.replace(Strings.EMPTY, Strings.EMPTY, Strings.EMPTY);
+        } catch (final UnsupportedOperationException ignored) {
+            immutable = true;
+        }

Review Comment:
   All the immutable maps in JDK (`Collections` and `ImmutableCollections`) I 
found throw on `Map#replace`.
   
   I get your point, but I think the chances this issue resurfaces in the 
future, because an implementation allows `Map#replace` but does not implement 
other methods, is slim.
   Adding `new HashMap` will incur in an allocation even if the map is already 
mutable.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to