[logback-dev] [JIRA] Resolved: (LBCLASSIC-51) Use of BasicStatusManager.iterator() without synchronization in ch.qos.logback.classic.jmx.Configurator

Ceki Gulcu (JIRA) noreply-jira at qos.ch
Wed Oct 29 17:04:21 CET 2008


     [ http://jira.qos.ch/browse/LBCLASSIC-51?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Ceki Gulcu resolved LBCLASSIC-51.
---------------------------------

    Fix Version/s: 0.9.10
       Resolution: Fixed

> Use of BasicStatusManager.iterator() without synchronization in ch.qos.logback.classic.jmx.Configurator
> -------------------------------------------------------------------------------------------------------
>
>                 Key: LBCLASSIC-51
>                 URL: http://jira.qos.ch/browse/LBCLASSIC-51
>             Project: logback-classic
>          Issue Type: Bug
>          Components: Other
>    Affects Versions: unspecified
>         Environment: Operating System: Windows
> Platform: PC
>            Reporter: Joern Huxhorn
>            Assignee: Ceki Gulcu
>             Fix For: 0.9.10
>
>
> 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;
>   }

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.qos.ch/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the logback-dev mailing list