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

concurrent modification exception when using list appender

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.11.1
    • Fix Version/s: 3.0.0, 2.11.2
    • Component/s: None
    • Labels:
      None

      Description

      Maybe this is intended and expected, but in case it is not I thought I report it.
      When you use the ListAppender and then when you verify the log events using some iteration like streams or in Groovy (using Spock) like

      ListAppender.getListAppender('Test Appender').events.findAll { it.thrown }.each { throw it.thrown }

      and while you iterate there are new log events, you get concurrent modification exceptions as the returned list (also for other methods like getMessages or getData) is backed by the original list when you use `Collections.unmodifiableList`.

      If this is not expected, maybe it should instead return a copy of the underlying collections. If it is intended, maybe a second set of methods would make sense that return a snapshot at call time.

      My current workaround is to copy the returned list like

      new ArrayList<>(ListAppender.getListAppender('Test Appender').events).findAll { it.thrown }.each { throw it.thrown }

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                ckozak Carter Kozak
                Reporter:
                vampire Björn Kautler
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 1h
                  1h