Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 313490 - ConcurrentModificationException during synchronizing artifact repository (p2.directorywatcher)
Summary: ConcurrentModificationException during synchronizing artifact repository (p2....
Status: RESOLVED FIXED
Alias: None
Product: Equinox
Classification: Eclipse Project
Component: p2 (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.6 RC2   Edit
Assignee: DJ Houghton CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-05-19 05:22 EDT by Katya Stoycheva CLA
Modified: 2010-05-20 14:32 EDT (History)
2 users (show)

See Also:
dj.houghton: review+
thomas: review+


Attachments
structure traversal with iterator is replaced with iterating array copy of the structure (1.49 KB, patch)
2010-05-19 05:25 EDT, Katya Stoycheva CLA
dj.houghton: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Katya Stoycheva CLA 2010-05-19 05:22:06 EDT
Build Identifier: 3.6.0.N20100512-2000

When synchronizing artifact repository (triggered by adding a bundle in dropins folder), ConcurrentModificationException is produced because of modifying underlying structure after the iterator is obtained.

Here is the code that cause the exception (synchronizeArtifactRepository method):
...
if (removedFiles.contains(artifactFile))		   			            artifactRepository.removeDescriptor(descriptor);
...

Reproducible: Always

Steps to Reproduce:
1.Download and unzip Equinox (http://download.eclipse.org/equinox/drops/N20100512-2000/index.php)
2.Start it in root folder (equinox) using 
java -jar plugins/org.eclipse.osgi_3.6.0.N20100512-2000.jar -configuration configuration –console
3.Setup dropins folder in config.ini:
org.eclipse.equinox.p2.reconciler.dropins.directory=dropins
4.Describe all plugins (and start them) in 
Equinox/configuration/org.eclipse.equinox.simpleconfigurator/bundles.info
5.Add some plugins in dropins folder
6.When dropins reconciler is started, observe the ConcurrentModificationException in logs:
!ENTRY org.eclipse.equinox.p2.reconciler.dropins 4 0 2010-05-14 16:11:44.463
!MESSAGE 
!STACK 0
org.osgi.framework.BundleException: Exception in org.eclipse.equinox.internal.p2.reconciler.dropins.Activator.start() of bundle org.eclipse.equinox.p2.reconciler.dropins.
	at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:806)
	at org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:755)
	at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:370)
	at org.eclipse.osgi.framework.internal.core.AbstractBundle.resume(AbstractBundle.java:374)
	at org.eclipse.osgi.framework.internal.core.Framework.resumeBundle(Framework.java:1067)
	at org.eclipse.osgi.framework.internal.core.StartLevelManager.resumeBundles(StartLevelManager.java:561)
	at org.eclipse.osgi.framework.internal.core.StartLevelManager.resumeBundles(StartLevelManager.java:546)
	at org.eclipse.osgi.framework.internal.core.StartLevelManager.incFWSL(StartLevelManager.java:459)
	at org.eclipse.osgi.framework.internal.core.StartLevelManager.doSetStartLevel(StartLevelManager.java:243)
	at org.eclipse.osgi.framework.internal.core.StartLevelManager.dispatchEvent(StartLevelManager.java:440)
	at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:227)
	at org.eclipse.osgi.framework.eventmgr.EventManager$EventThread.run(EventManager.java:337)
Caused by: java.util.ConcurrentModificationException
	at java.util.AbstractList$Itr.checkForComodification(Unknown Source)
	at java.util.AbstractList$Itr.next(Unknown Source)
	at org.eclipse.equinox.internal.p2.metadata.expression.RepeatableIterator.next(RepeatableIterator.java:82)
	at org.eclipse.equinox.internal.p2.metadata.expression.CompoundIterator.positionNext(CompoundIterator.java:76)
	at org.eclipse.equinox.internal.p2.metadata.expression.CompoundIterator.hasNext(CompoundIterator.java:43)
	at org.eclipse.equinox.internal.p2.metadata.expression.CompoundIterator.positionNext(CompoundIterator.java:69)
	at org.eclipse.equinox.internal.p2.metadata.expression.CompoundIterator.hasNext(CompoundIterator.java:43)
	at org.eclipse.equinox.internal.p2.metadata.expression.RepeatableIterator$IndexProviderIterator.hasNext(RepeatableIterator.java:142)
	at org.eclipse.equinox.internal.provisional.p2.directorywatcher.RepositoryListener.synchronizeArtifactRepository(RepositoryListener.java:241)
	at org.eclipse.equinox.internal.provisional.p2.directorywatcher.RepositoryListener.stopPoll(RepositoryListener.java:199)
	at org.eclipse.equinox.internal.p2.reconciler.dropins.DropinsRepositoryListener.stopPoll(DropinsRepositoryListener.java:236)
	at org.eclipse.equinox.internal.provisional.p2.directorywatcher.DirectoryWatcher.stopPoll(DirectoryWatcher.java:171)
	at org.eclipse.equinox.internal.provisional.p2.directorywatcher.DirectoryWatcher.poll(DirectoryWatcher.java:109)
	at org.eclipse.equinox.internal.p2.reconciler.dropins.Activator.watchDropins(Activator.java:476)
	at org.eclipse.equinox.internal.p2.reconciler.dropins.Activator.start(Activator.java:160)
	at org.eclipse.osgi.framework.internal.core.BundleContextImpl$1.run(BundleContextImpl.java:783)
	at java.security.AccessController.doPrivileged(Native Method)
	at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:774)
	... 11 more
Root exception:
java.util.ConcurrentModificationException
	at java.util.AbstractList$Itr.checkForComodification(Unknown Source)
	at java.util.AbstractList$Itr.next(Unknown Source)
	at org.eclipse.equinox.internal.p2.metadata.expression.RepeatableIterator.next(RepeatableIterator.java:82)
	at org.eclipse.equinox.internal.p2.metadata.expression.CompoundIterator.positionNext(CompoundIterator.java:76)
	at org.eclipse.equinox.internal.p2.metadata.expression.CompoundIterator.hasNext(CompoundIterator.java:43)
	at org.eclipse.equinox.internal.p2.metadata.expression.CompoundIterator.positionNext(CompoundIterator.java:69)
	at org.eclipse.equinox.internal.p2.metadata.expression.CompoundIterator.hasNext(CompoundIterator.java:43)
	at org.eclipse.equinox.internal.p2.metadata.expression.RepeatableIterator$IndexProviderIterator.hasNext(RepeatableIterator.java:142)
	at org.eclipse.equinox.internal.provisional.p2.directorywatcher.RepositoryListener.synchronizeArtifactRepository(RepositoryListener.java:241)
	at org.eclipse.equinox.internal.provisional.p2.directorywatcher.RepositoryListener.stopPoll(RepositoryListener.java:199)
	at org.eclipse.equinox.internal.p2.reconciler.dropins.DropinsRepositoryListener.stopPoll(DropinsRepositoryListener.java:236)
	at org.eclipse.equinox.internal.provisional.p2.directorywatcher.DirectoryWatcher.stopPoll(DirectoryWatcher.java:171)
	at org.eclipse.equinox.internal.provisional.p2.directorywatcher.DirectoryWatcher.poll(DirectoryWatcher.java:109)
	at org.eclipse.equinox.internal.p2.reconciler.dropins.Activator.watchDropins(Activator.java:476)
	at org.eclipse.equinox.internal.p2.reconciler.dropins.Activator.start(Activator.java:160)
	at org.eclipse.osgi.framework.internal.core.BundleContextImpl$1.run(BundleContextImpl.java:783)
	at java.security.AccessController.doPrivileged(Native Method)
	at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:774)
	at org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:755)
	at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:370)
	at org.eclipse.osgi.framework.internal.core.AbstractBundle.resume(AbstractBundle.java:374)
	at org.eclipse.osgi.framework.internal.core.Framework.resumeBundle(Framework.java:1067)
	at org.eclipse.osgi.framework.internal.core.StartLevelManager.resumeBundles(StartLevelManager.java:561)
	at org.eclipse.osgi.framework.internal.core.StartLevelManager.resumeBundles(StartLevelManager.java:546)
	at org.eclipse.osgi.framework.internal.core.StartLevelManager.incFWSL(StartLevelManager.java:459)
	at org.eclipse.osgi.framework.internal.core.StartLevelManager.doSetStartLevel(StartLevelManager.java:243)
	at org.eclipse.osgi.framework.internal.core.StartLevelManager.dispatchEvent(StartLevelManager.java:440)
	at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:227)
	at org.eclipse.osgi.framework.eventmgr.EventManager$EventThread.run(EventManager.java:337)
Comment 1 Katya Stoycheva CLA 2010-05-19 05:25:39 EDT
Created attachment 169075 [details]
structure traversal with iterator is replaced with iterating array copy of the structure

May result in slight increasing memory consumption due to array copy
Comment 2 Pascal Rapicault CLA 2010-05-19 22:20:11 EDT
I'm surprised that we have not yet run into this. I've looked at the patch and it looks good.
Comment 3 DJ Houghton CLA 2010-05-20 14:32:27 EDT
Thanks for the patch! 
Fix released.