Title: Possible Synchronization Issue in UnifiedLoaderRepository2

Hi folks,

I am running the Jakarta James mail server in Jboss_3.0.2 and I'm frequently seeing ConcurrentModificationExceptions in the UnifiedLoaderRepository2 while Javamail is attempting to load it's protocol provider and address map properties files.  The full exception is:

    java.util.ConcurrentModificationException
        at java.util.HashMap$HashIterator.nextEntry(HashMap.java:762)
        at java.util.HashMap$KeyIterator.next(HashMap.java:798)
        at org.jboss.mx.loading.UnifiedLoaderRepository2.getResourceFromRepository(UnifiedLoaderRepository2.java:344)
        at org.jboss.mx.loading.UnifiedLoaderRepository2.getResource(UnifiedLoaderRepository2.java:295)
        at org.jboss.mx.loading.UnifiedClassLoader.getResource(UnifiedClassLoader.java:296)
        at java.lang.ClassLoader.getResourceAsStream(ClassLoader.java:941)
        at java.lang.Class.getResourceAsStream(Class.java:1298)
        at javax.mail.Session.loadProviders(Session.java:771)
        at javax.mail.Session.<init>(Session.java:81)
        at javax.mail.Session.getInstance(Session.java:103)
        at org.apache.james.transport.mailets.RemoteDelivery.run(Unknown Source)
        at java.lang.Thread.run(Thread.java:536

I've taken a quick look at the UnifiedLoaderRepository2.java source file and it looks like there's something amiss with the synchronization around the classloader HashSets and their iterators.  Here's what the key methods do:

  - loadClassFromRepository has no synchronization.
  - getResourceFromRepository has no synchronization.
  - getURLs synchronizes on the object instance (this).
  - addClassLoader synchronizes at the class level (UnifiedLoaderRepository2.class)
  - removeClassLoader synchronizes at the class level (UnifiedLoaderRepository2.class)
  - findClass synchronizes on the object instance (this).

When I change them all to synchronize on the object instance, everything seems to work OK.

Steve

Reply via email to