Uploaded image for project: 'logback'
  1. logback
  2. LOGBACK-1299

ConcurrentModificationException when calling LoggerContext#addListener

    XMLWordPrintable

Details

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Critical Critical
    • None
    • 1.2.3
    • logback-classic
    • None

    Description

      LoggerContext#addListener modifies an ArrayList in LoggerContext#loggerContextListenerList

      If tried to search for other jira issues related to this, and it seems that LOGBACK-1239 has hit the same issue.

      The core issue is that thread A triggers a reset (via reload of config or JMXConfigurator. While LoggerContext#loggerContextListenerList is being iterated over, thread B calls LoggerContext#addListener.

      A simple way to reproduce this is:

      LoggerContext context = new LoggerContext();
      context.start();
      
      context.addListener(new LoggerContextListener(){
       
       @Override
       public void onReset(LoggerContext context){
           context.addListener(this);
       }
       
       @Override public boolean isResetResistant(){ return false;}
       
       @Override public void onStart(LoggerContext context){}
       
       @Override public void onStop(LoggerContext context){}
      
      @Override public void onLevelChange(Logger logger, Level level){}
      });
      
      context.reset();
      

      Which fails with:

      java.util.ConcurrentModificationException
       at java.util.ArrayList$Itr.checkForComodification(ArrayList.java:901)
       at java.util.ArrayList$Itr.next(ArrayList.java:851)
       at ch.qos.logback.classic.LoggerContext.fireOnReset(LoggerContext.java:323)
       at ch.qos.logback.classic.LoggerContext.reset(LoggerContext.java:226)
      

       

      Attachments

        Activity

          People

            logback-dev Logback dev list
            eiden Christoffer Eide
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: