You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@logging.apache.org by "Kenny MacLeod (JIRA)" <ji...@apache.org> on 2017/05/05 01:46:04 UTC

[jira] [Created] (LOG4J2-1893) JdkMapAdapterStringMap#toMap can return an immutable map

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)