You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jackrabbit.apache.org by "Stefan Guggisberg (JIRA)" <ji...@apache.org> on 2007/01/19 14:07:29 UTC

[jira] Assigned: (JCR-713) ConcurrentModificationException during registration of nodetypes

     [ https://issues.apache.org/jira/browse/JCR-713?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Stefan Guggisberg reassigned JCR-713:
-------------------------------------

    Assignee: Stefan Guggisberg

> ConcurrentModificationException during registration of nodetypes
> ----------------------------------------------------------------
>
>                 Key: JCR-713
>                 URL: https://issues.apache.org/jira/browse/JCR-713
>             Project: Jackrabbit
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 1.1.1
>            Reporter: Martijn Hendriks
>         Assigned To: Stefan Guggisberg
>
> During the registration of a set of nodetypes this exception may be encountered:
> java.util.ConcurrentModificationException
>         at org.apache.commons.collections.map.AbstractReferenceMap$ReferenceEntrySetIterator.checkMod(AbstractReferenceMap.java:761)
>         at org.apache.commons.collections.map.AbstractReferenceMap$ReferenceEntrySetIterator.hasNext(AbstractReferenceMap.java:735)
>         at org.apache.jackrabbit.core.nodetype.NodeTypeRegistry.notifyRegistered(NodeTypeRegistry.java:1750)
>         at org.apache.jackrabbit.core.nodetype.NodeTypeRegistry.registerNodeTypes(NodeTypeRegistry.java:223)
> It seems that the copying of the listeners triggered this exception:
>     private void notifyRegistered(QName ntName) {
>         // copy listeners to array to avoid ConcurrentModificationException
>         NodeTypeRegistryListener[] la =
>                 new NodeTypeRegistryListener[listeners.size()];
>         Iterator iter = listeners.values().iterator();
>         int cnt = 0;
> 1750:   while (iter.hasNext()) {
>             la[cnt++] = (NodeTypeRegistryListener) iter.next();
>         }
>         for (int i = 0; i < la.length; i++) {
>             if (la[i] != null) {
>                 la[i].nodeTypeRegistered(ntName);
>             }
>         }
>     }
> The methods "notifyReRegistered" and "notifyUnregistered" will probably suffer from the same problem.
> Reproduction of this exception may be tricky; it only occurred once in our application. It is probably a race condition: another thread might access the listeners during the copy. It may be helpful to use a debugger and set a breakpoint in the middle of the copy giving other threads the opportunity to access the listeners...
> We think that a possible solution is the following:
>     /**
>      * Notify the listeners that a node type <code>ntName</code> has been registered.
>      */
>     private void notifyRegistered(QName ntName) {
>         // copy listeners to array to avoid ConcurrentModificationException
>     	NodeTypeRegistryListener[] la;
>     	synchronized (listeners) {
>             la = (NodeTypeRegistryListener[]) listeners.values().toArray(new NodeTypeRegistryListener[listeners.size()]);
> 		}
>         for (int i = 0; i < la.length; i++) {
>             if (la[i] != null) {
>                 la[i].nodeTypeRegistered(ntName);
>             }
>         }
>     }

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