You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by "Marius Volkhart (Jira)" <ji...@apache.org> on 2020/02/23 15:00:06 UTC

[jira] [Created] (LOG4J2-2788) Replace ThreadContext.EmptyIterator with JDK variant

Marius Volkhart created LOG4J2-2788:
---------------------------------------

             Summary: Replace ThreadContext.EmptyIterator with JDK variant
                 Key: LOG4J2-2788
                 URL: https://issues.apache.org/jira/browse/LOG4J2-2788
             Project: Log4j 2
          Issue Type: Story
          Components: Core
    Affects Versions: 2.13.0
            Reporter: Marius Volkhart


{{ThreadContext.java}} has a class, {{EmptyIterator}}, used in conjunction with the {{EmptyThreadContextStack}}. I'd like to propose replacing it with {{Collections.emptyIterator()}}.

It was unclear from the comments and commit messages whether or not the {{EmptyIterator}} was used because {{Collections.emptyIterator()}} was not available, or because it was deemed unfit at the time. Log4J 2 requires Java 8 now, so using Java 7 classes is possible. 

Switching to the JDK variant results in a slight change in behavior. The {{EmptyIterator}} no-ops on a call to {{remove()}}. The JDK variant throws an {{IllegalStateException}}. This seems acceptable since all other mutator methods of the {{EmptyThreadContextStack}} throw an {{UnsupportedOperationException}}. While the exceptions aren't the same, it's clear that mutating isn't supported.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)