Repository: logging-log4j2 Updated Branches: refs/heads/master 9d18e96ed -> 11101ce44
LOG4J2-1611 LOG4J2-1010 bugfix: ensure the returned JdkMapAdapterStringMap is frozen to prevent downstream components from attempting to modify it (which will result in UnsupportedOperationExceptions if the underlying map is unmodifiable) Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/11101ce4 Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/11101ce4 Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/11101ce4 Branch: refs/heads/master Commit: 11101ce44b5da038ab8af0c50dc294c94055f70c Parents: 9d18e96 Author: rpopma <rpo...@apache.org> Authored: Sun Sep 25 00:42:27 2016 +0900 Committer: rpopma <rpo...@apache.org> Committed: Sun Sep 25 00:42:27 2016 +0900 ---------------------------------------------------------------------- .../log4j/core/impl/ThreadContextDataInjector.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/11101ce4/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ThreadContextDataInjector.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ThreadContextDataInjector.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ThreadContextDataInjector.java index 810eaf8..210c5da 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ThreadContextDataInjector.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ThreadContextDataInjector.java @@ -75,8 +75,9 @@ public class ThreadContextDataInjector { // If there are no configuration properties returning a thin wrapper around the copy // is faster than copying the elements into the LogEvent's reusable StringMap. if (props == null || props.isEmpty()) { - // this will replace the LogEvent's context data with the returned instance - return copy.isEmpty() ? EMPTY_STRING_MAP : new JdkMapAdapterStringMap(copy); + // this will replace the LogEvent's context data with the returned instance. + // NOTE: must mark as frozen or downstream components may attempt to modify (UnsupportedOperationEx) + return copy.isEmpty() ? EMPTY_STRING_MAP : frozenStringMap(copy); } // If the list of Properties is non-empty we need to combine the properties and the ThreadContext // data. Note that we cannot reuse the specified StringMap: some Loggers may have properties defined @@ -93,6 +94,12 @@ public class ThreadContextDataInjector { return result; } + private static JdkMapAdapterStringMap frozenStringMap(final Map<String, String> copy) { + final JdkMapAdapterStringMap result = new JdkMapAdapterStringMap(copy); + result.freeze(); + return result; + } + @Override public ReadOnlyStringMap rawContextData() { final ThreadContextMap map = ThreadContextAccess.getThreadContextMap();