Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 322227 - ConcurrentModificationException during EMF model initialization
Summary: ConcurrentModificationException during EMF model initialization
Status: RESOLVED FIXED
Alias: None
Product: WTP Java EE Tools
Classification: WebTools
Component: jst.j2ee (show other bugs)
Version: 3.2   Edit
Hardware: PC Windows XP
: P3 major (vote)
Target Milestone: 3.2.2   Edit
Assignee: Carl Anderson CLA
QA Contact: Chuck Bridgham CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-08-10 09:19 EDT by Carl Anderson CLA
Modified: 2010-08-11 17:29 EDT (History)
1 user (show)

See Also:
cbridgha: review+


Attachments
Protect the initializePackageContents with a lock (357.36 KB, patch)
2010-08-10 09:30 EDT, Carl Anderson CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Carl Anderson CLA 2010-08-10 09:19:26 EDT
An adopter product is seeing the following exception:

Caused by: java.util.ConcurrentModificationException
    at org.eclipse.emf.common.util.AbstractEList$EIterator.checkModCount(AbstractEList.java:762)
    at org.eclipse.emf.common.util.AbstractEList$EIterator.doNext(AbstractEList.java:710)
    at org.eclipse.emf.common.util.AbstractEList$EIterator.next(AbstractEList.java:696)
    at org.eclipse.emf.ecore.impl.ESuperAdapter.setFlags(ESuperAdapter.java:376)
    at org.eclipse.emf.ecore.impl.EClassImpl$11.setFlags(EClassImpl.java:2112)
    at org.eclipse.emf.ecore.impl.ESuperAdapter.notifyChanged(ESuperAdapter.java:195)
    at org.eclipse.emf.common.notify.impl.BasicNotifierImpl.eNotify(BasicNotifierImpl.java:380)
    at org.eclipse.emf.common.notify.impl.NotificationImpl.dispatch(NotificationImpl.java:1033)
    at org.eclipse.emf.common.notify.impl.NotifyingListImpl.addUnique(NotifyingListImpl.java:367)
    at org.eclipse.emf.common.util.AbstractEList.add(AbstractEList.java:345)
    at org.eclipse.emf.ecore.impl.EClassImpl$9.delegateAdd(EClassImpl.java:1698)
    at org.eclipse.emf.ecore.impl.EClassImpl$9.delegateAdd(EClassImpl.java:1)
    at org.eclipse.emf.common.util.DelegatingEList.addUnique(DelegatingEList.java:340)
    at org.eclipse.emf.common.notify.impl.DelegatingNotifyingListImpl.doAddUnique(DelegatingNotifyingListImpl.java:385)
    at org.eclipse.emf.common.notify.impl.DelegatingNotifyingListImpl.addUnique(DelegatingNotifyingListImpl.java:281)
    at org.eclipse.emf.common.util.AbstractEList.add(AbstractEList.java:307)
    at org.eclipse.jst.j2ee.common.internal.impl.CommonPackageImpl.initializePackageContents(CommonPackageImpl.java:1356)
    at org.eclipse.jst.j2ee.common.internal.impl.CommonPackageImpl.init(CommonPackageImpl.java:296)
    at org.eclipse.jst.j2ee.common.CommonPackage.<clinit>(CommonPackage.java:243)
    at java.lang.J9VMInternals.initializeImpl(Native Method)
    at java.lang.J9VMInternals.initialize(J9VMInternals.java:200)
    ... 80 more

What causes this is that an element of the PackageImpl (in this case compatibilityDescriptionGroupEClass) is being updated in one package (in this case the CommonPackage) in initializePackageContents() while that same element is modified in another package's initializePackageContents() on another thread.
Comment 1 Carl Anderson CLA 2010-08-10 09:30:02 EDT
Created attachment 176237 [details]
Protect the initializePackageContents with a lock

The section of initializePackageContents() that actually modifies the EMF model needs to be made thread safe.  I am doing that by introducing a common lock that must be acquired before the initializePackageContents() can modify the contents.  This should prevent a ConcurrentModificationException.
Comment 2 Carl Anderson CLA 2010-08-10 09:31:45 EDT
Note that the patch appears to be a much larger change than it is, since the package contents initialization is moved inside of a try/catch block.  The actual initialization code has not been modified.
Comment 3 Chuck Bridgham CLA 2010-08-11 16:25:16 EDT
approve
Comment 4 Carl Anderson CLA 2010-08-11 17:29:53 EDT
Committed to HEAD for WTP 3.2.2 and WTP 3.3