Kenny MacLeod created LOG4J2-1893: ------------------------------------- Summary: JdkMapAdapterStringMap#toMap can return an immutable map Key: LOG4J2-1893 URL: https://issues.apache.org/jira/browse/LOG4J2-1893 Project: Log4j 2 Issue Type: Bug Components: Core Affects Versions: 2.8.2 Reporter: Kenny MacLeod Priority: Minor
The Javadoc for {{ReadOnlyStringMap#toMap}} states that bq. Returns a non-null mutable Map<String, String> containing a snapshot of this data structure In the case of {{JdkMapAdapterStringMap}}, the {{toMap}} method just returns whatever map was passed in to its constructor, so there's no guarantee of its mutability. In fact, {{ThreadContextDataInjector#injectContextData}} creates a {{JdkMapAdapterStringMap}} explicitly with an immutable map. The obvious fix is for {{JdkMapAdapterStringMap}} to clone the map before returning it from {{toMap}}, which not only guarantees the method constract is fulfilled, but also protects the internals of {{JdkMapAdapterStringMap}} from inadvertent modification by whoever calls {{toMap}}. -- This message was sent by Atlassian JIRA (v6.3.15#6346)