[logback-dev] [Bug 148] New: Use of BasicStatusManager.iterator() without synchronization in ch.qos.logback.classic.jmx.Configurator

bugzilla-daemon at pixie.qos.ch bugzilla-daemon at pixie.qos.ch
Tue Apr 22 12:31:07 CEST 2008


http://bugzilla.qos.ch/show_bug.cgi?id=148

           Summary: Use of BasicStatusManager.iterator() without
                    synchronization in
                    ch.qos.logback.classic.jmx.Configurator
           Product: logback-classic
           Version: unspecified
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: major
          Priority: P1
         Component: Other
        AssignedTo: logback-dev at qos.ch
        ReportedBy: joern at huxhorn.de


We sometimes receive strange exceptions in our webapp:
[21/Apr/2008:21:00:58] warning ( 1596):         CORE3283: stderr: Exception in
thread "Thread-6" java.lang.ArrayIndexOutOfBoundsException 
[21/Apr/2008:21:00:58] warning ( 1596):         CORE3283: stderr: at
java.lang.System.arraycopy(Native Method) 
[21/Apr/2008:21:00:58] warning ( 1596):         CORE3283: stderr: at
java.util.ArrayList.ensureCapacity(ArrayList.java:170) 
[21/Apr/2008:21:00:58] warning ( 1596):         CORE3283: stderr: at
java.util.ArrayList.add(ArrayList.java:351) 
[21/Apr/2008:21:00:58] warning ( 1596):         CORE3283: stderr: at
ch.qos.logback.core.BasicStatusManager.add(BasicStatusManager.java:38) 
[21/Apr/2008:21:00:58] warning ( 1596):         CORE3283: stderr: at
ch.qos.logback.core.spi.ContextAwareBase.addStatus(ContextAwareBase.java:59) 
[21/Apr/2008:21:00:58] warning ( 1596):         CORE3283: stderr: at
ch.qos.logback.core.spi.ContextAwareBase.addInfo(ContextAwareBase.java:64) 

I just tried to analyze the problem and found out that
ch.qos.logback.classic.jmx.Configurator is simply using the iterator of the
status manager without synchronizing, as it's documented in BasicStatusManager.

So instead of
  public List<String> getStatuses() {
    List<String> list = new ArrayList<String>();
    Iterator<Status> it = context.getStatusManager().iterator();
    while(it.hasNext()) {
      list.add(it.next().toString());
    }
    return list;
  }
it should probably be 
  public List<String> getStatuses() {
    List<String> list = new ArrayList<String>();
    StatusManager sm = context.getStatusManager();
    Iterator<Status> it = sm.iterator();
    synchronized(sm) {
      while(it.hasNext()) {
        list.add(it.next().toString());
      }
    }
    return list;
  }


-- 
Configure bugmail: http://bugzilla.qos.ch/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.



More information about the logback-dev mailing list