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

Use of BasicStatusManager.iterator() without synchronization in ch.qos.logback.classic.jmx.Configurator

    XMLWordPrintable

Details

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major Major
    • 0.9.10
    • None
    • logback-classic
    • None
    • Operating System: Windows
      Platform: PC

    • 148

    Description

      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;
      }

      Attachments

        Activity

          People

            ceki Ceki Gülcü
            joern@huxhorn.de Joern Huxhorn
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: