Uploaded image for project: 'Log4j 2'
  1. Log4j 2
  2. LOG4J2-2788

Replace ThreadContext.EmptyIterator with JDK variant

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • 2.13.0
    • None
    • Core
    • None

    Description

      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.

      Attachments

        Activity

          People

            pkarwasz Piotr Karwasz
            mariusvolkhart Marius Volkhart
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: