excalibur-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Kazimierz Pogoda (JIRA)" <...@excalibur.apache.org>
Subject [jira] Commented: (EXLBR-26) org.apache.avalon.excalibur.monitor.impl.ActiveMonitor is not thread safe
Date Mon, 18 Jul 2005 13:24:31 GMT
    [ http://issues.apache.org/jira/browse/EXLBR-26?page=comments#action_12316034 ] 

Kazimierz Pogoda commented on EXLBR-26:
---------------------------------------

OK, you are right :)

I misunderstood the api. So i've changed the test as you did (resource with unique file for
every thread - new FileResource("/tmp/" + i), and now i've got this stacktrace:

Exception in thread "Thread-0" java.util.NoSuchElementException
	at java.util.HashMap$HashIterator.nextEntry(HashMap.java:790)
	at java.util.HashMap$ValueIterator.next(HashMap.java:817)
	at java.util.AbstractCollection.toArray(AbstractCollection.java:176)
	at org.apache.avalon.excalibur.monitor.impl.AbstractMonitor.getResources(AbstractMonitor.java:152)
	at org.apache.avalon.excalibur.monitor.impl.AbstractMonitor.scanAllResources(AbstractMonitor.java:161)
	at org.apache.avalon.excalibur.monitor.impl.ActiveMonitor.run(ActiveMonitor.java:136)
	at java.lang.Thread.run(Thread.java:595)

or:

Exception in thread "Thread-0" java.lang.NullPointerException
	at org.apache.avalon.excalibur.monitor.impl.AbstractMonitor.scanAllResources(AbstractMonitor.java:164)
	at org.apache.avalon.excalibur.monitor.impl.ActiveMonitor.run(ActiveMonitor.java:136)
	at java.lang.Thread.run(Thread.java:595)

My enviroment:
linux 2.6.x
java version "1.5.0_03"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_03-b07)
Java HotSpot(TM) Client VM (build 1.5.0_03-b07, mixed mode, sharing)
excalibur-monitor-1.0.2.jar

IMHO the bug is caused by the following thing:

protected Resource[] getResources()                                         
{                                                                           
    final Collection collection = m_resources.values();                     
    return (Resource[])collection.toArray( new Resource[ collection.size() ] );
} 

If Thread1 calls collection.size() and allocates new array with this size and then goes inside
toArray() method, then VM can switch to Thread2 which can change number of elements in m_resources
map during execution of toArray(). So we can expect NoSuchElementException and ConcurrentModificationException
(from iterator), and also NullPointerException if last elements in array returned by toArray()
method are null.

There is another thing i want to notice:

public final void removeResource( final String key )

Can throw NullPointerException if there is no resource with given key. It should be documented,
and maybe changed to IllegalArgumentException or event checked exception.



> org.apache.avalon.excalibur.monitor.impl.ActiveMonitor is not thread safe
> -------------------------------------------------------------------------
>
>          Key: EXLBR-26
>          URL: http://issues.apache.org/jira/browse/EXLBR-26
>      Project: Excalibur Components
>         Type: Bug
>   Components: Monitor
>     Versions: 1.0.2
>  Environment: Linux 2.6.11 + jdk5.0
>     Reporter: Kazimierz Pogoda

>
> getResources() method of the AbstractMonitor should be probably synchronized on m_resources
like the other methods in this class.

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


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@excalibur.apache.org
For additional commands, e-mail: dev-help@excalibur.apache.org


Mime
View raw message