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

Joern Huxhorn (JIRA) noreply-jira at qos.ch
Sun Oct 19 14:38:21 CEST 2008


    [ http://jira.qos.ch/browse/LBCLASSIC-51?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=10790#action_10790 ] 

Joern Huxhorn commented on LBCLASSIC-51:
----------------------------------------

I think the described problem might also be the reason for http://jira.qos.ch/browse/LBCLASSIC-14

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