Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 305429

Summary: Sporadic ConcurrentModificationException when importing existing plugin projects
Product: [Eclipse Project] PDE Reporter: Brian de Alwis <bsd>
Component: UIAssignee: Darin Wright <darin.eclipse>
Status: RESOLVED FIXED QA Contact:
Severity: critical    
Priority: P3 CC: darin.eclipse, eclipse, jcompagner, karasiuk, leo.dos.santos, nicolas.bros
Version: 3.6   
Target Milestone: 3.6 M7   
Hardware: Macintosh   
OS: Mac OS X   
Whiteboard:
Attachments:
Description Flags
Binary plugin project for LarvaLabs' Java5-enabled commons-collections variant
none
alternate patch none

Description Brian de Alwis CLA 2010-03-10 18:14:56 EST
Build: e4 I20100310-0900 (based on Eclipse SDK 3.6.0.v201003090809)

[I've marked this problem as critical as the problem is utterly baffling when it occurs, and it's not possible to run your target image.]

I just switched to the latest e4 I build, and found that my workspace spontaneously gave up the ghost: many of the source plugins in my workspace could no longer resolve other plugins, even though they were defined in the workspace.  Many of the plugins were no longer listed in debug launch configurations.

I seem to remember having had this problem once before.  At that time, I ended up blowing away my .metadata and reconstructing my workspace by importing the various projects.  I proceeded to do this, but found that the problem reappeared.

After a lot of futzing around (trying previous I builds, going back to 1.0M4, but always having the problem), I finally looke at the .log and saw that there was a ConcurrentModificationException being thrown during the import.  I've since narrowed the problem down to importing a single binary bundle (to be attached).  This is repeatable.  

Once this CME occurs, any bundles other imported along with this specific bundle are in an inconsistent state with PDE.  And it also seems that any User Libraries may become messed up too.


!ENTRY org.eclipse.jdt.core 4 2 2010-03-10 17:53:12.058
!MESSAGE Problems occurred when invoking code from plug-in: "org.eclipse.jdt.core".
!STACK 0
java.util.ConcurrentModificationException
	at java.util.TreeMap$PrivateEntryIterator.nextEntry(TreeMap.java:1100)
	at java.util.TreeMap$EntryIterator.next(TreeMap.java:1136)
	at java.util.TreeMap$EntryIterator.next(TreeMap.java:1131)
	at org.eclipse.pde.internal.core.bundle.BundleModel.load(BundleModel.java:66)
	at org.eclipse.pde.internal.core.WorkspaceModelManager.loadModel(WorkspaceModelManager.java:247)
	at org.eclipse.pde.internal.core.WorkspacePluginModelManager.createModel(WorkspacePluginModelManager.java:65)
	at org.eclipse.pde.internal.core.WorkspacePluginModelManager.handleBundleManifestDelta(WorkspacePluginModelManager.java:286)
	at org.eclipse.pde.internal.core.WorkspacePluginModelManager.handleFileDelta(WorkspacePluginModelManager.java:133)
	at org.eclipse.pde.internal.core.WorkspaceModelManager.visit(WorkspaceModelManager.java:160)
	at org.eclipse.core.internal.events.ResourceDelta.accept(ResourceDelta.java:68)
	at org.eclipse.core.internal.events.ResourceDelta.accept(ResourceDelta.java:79)
	at org.eclipse.core.internal.events.ResourceDelta.accept(ResourceDelta.java:79)
	at org.eclipse.core.internal.events.ResourceDelta.accept(ResourceDelta.java:79)
	at org.eclipse.core.internal.events.ResourceDelta.accept(ResourceDelta.java:48)
	at org.eclipse.pde.internal.core.WorkspaceModelManager.handleResourceDelta(WorkspaceModelManager.java:125)
	at org.eclipse.pde.internal.core.WorkspaceModelManager.resourceChanged(WorkspaceModelManager.java:113)
	at org.eclipse.jdt.internal.core.DeltaProcessingState$1.run(DeltaProcessingState.java:465)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
	at org.eclipse.jdt.internal.core.DeltaProcessingState.resourceChanged(DeltaProcessingState.java:460)
	at org.eclipse.core.internal.events.NotificationManager$2.run(NotificationManager.java:291)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
	at org.eclipse.core.internal.events.NotificationManager.notify(NotificationManager.java:285)
	at org.eclipse.core.internal.events.NotificationManager.broadcastChanges(NotificationManager.java:149)
	at org.eclipse.core.internal.resources.Workspace.broadcastPostChange(Workspace.java:327)
	at org.eclipse.core.internal.resources.Workspace.endOperation(Workspace.java:1181)
	at org.eclipse.core.internal.resources.InternalWorkspaceJob.run(InternalWorkspaceJob.java:45)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)

!ENTRY org.eclipse.jdt.core 4 4 2010-03-10 17:53:12.058
!MESSAGE Exception occurred in listener of pre Java resource change notification
!STACK 0
java.util.ConcurrentModificationException
	at java.util.TreeMap$PrivateEntryIterator.nextEntry(TreeMap.java:1100)
	at java.util.TreeMap$EntryIterator.next(TreeMap.java:1136)
	at java.util.TreeMap$EntryIterator.next(TreeMap.java:1131)
	at org.eclipse.pde.internal.core.bundle.BundleModel.load(BundleModel.java:66)
	at org.eclipse.pde.internal.core.WorkspaceModelManager.loadModel(WorkspaceModelManager.java:247)
	at org.eclipse.pde.internal.core.WorkspacePluginModelManager.createModel(WorkspacePluginModelManager.java:65)
	at org.eclipse.pde.internal.core.WorkspacePluginModelManager.handleBundleManifestDelta(WorkspacePluginModelManager.java:286)
	at org.eclipse.pde.internal.core.WorkspacePluginModelManager.handleFileDelta(WorkspacePluginModelManager.java:133)
	at org.eclipse.pde.internal.core.WorkspaceModelManager.visit(WorkspaceModelManager.java:160)
	at org.eclipse.core.internal.events.ResourceDelta.accept(ResourceDelta.java:68)
	at org.eclipse.core.internal.events.ResourceDelta.accept(ResourceDelta.java:79)
	at org.eclipse.core.internal.events.ResourceDelta.accept(ResourceDelta.java:79)
	at org.eclipse.core.internal.events.ResourceDelta.accept(ResourceDelta.java:79)
	at org.eclipse.core.internal.events.ResourceDelta.accept(ResourceDelta.java:48)
	at org.eclipse.pde.internal.core.WorkspaceModelManager.handleResourceDelta(WorkspaceModelManager.java:125)
	at org.eclipse.pde.internal.core.WorkspaceModelManager.resourceChanged(WorkspaceModelManager.java:113)
	at org.eclipse.jdt.internal.core.DeltaProcessingState$1.run(DeltaProcessingState.java:465)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
	at org.eclipse.jdt.internal.core.DeltaProcessingState.resourceChanged(DeltaProcessingState.java:460)
	at org.eclipse.core.internal.events.NotificationManager$2.run(NotificationManager.java:291)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
	at org.eclipse.core.internal.events.NotificationManager.notify(NotificationManager.java:285)
	at org.eclipse.core.internal.events.NotificationManager.broadcastChanges(NotificationManager.java:149)
	at org.eclipse.core.internal.resources.Workspace.broadcastPostChange(Workspace.java:327)
	at org.eclipse.core.internal.resources.Workspace.endOperation(Workspace.java:1181)
	at org.eclipse.core.internal.resources.InternalWorkspaceJob.run(InternalWorkspaceJob.java:45)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)
Comment 1 Brian de Alwis CLA 2010-03-10 18:17:21 EST
Created attachment 161696 [details]
Binary plugin project for LarvaLabs' Java5-enabled commons-collections variant

Importing this project (Import -> Existing Projects into Workspace) seems to reliably trigger the ConcurrentModificationException in BundleModel#load().
Comment 2 DJ Houghton CLA 2010-03-10 19:12:19 EST
Possible dup of bug 302766?
Comment 3 Brian de Alwis CLA 2010-03-10 19:20:15 EST
DJ, did you mean bug 304766?
Comment 4 Brian de Alwis CLA 2010-03-11 09:56:52 EST
I looked into the problem.   Fortunately it's a simple programming error rather than a race condition.

This problem is caused by a MANIFEST.MF header field with no value:

    Implementation-Vendor-Id:
    
 The code in BundleModel#load(InputStream,boolean) loads the MANIFEST.MF into a instance of Bundle, and then iterates over the Bundle's header, rewriting the values using Bundle.setHeader().  But Bundle.setHeader() will remove the header if the value is null or empty -- leading to the CME.  (Rewriting the same header being iterated against seems risque anyways.)
 
The following patch fixes the problem by iterating over a copy of the Bundle's header (against org.eclipse.pde.core v20100308).
 
--- src/org/eclipse/pde/internal/core/bundle/BundleModel.java.orig	2010-03-11 09:54:44.000000000 -0500
+++ src/org/eclipse/pde/internal/core/bundle/BundleModel.java	2010-03-11 09:54:52.000000000 -0500
@@ -60,7 +60,7 @@
 			setLoaded(true);
 			// format headers
 			BundleModelFactory factory = new BundleModelFactory(this);
-			Map headers = fBundle.getHeaders();
+			Map headers = new HashMap(fBundle.getHeaders());
 			Iterator it = headers.entrySet().iterator();
 			while (it.hasNext()) {
 				Entry entry = (Entry) it.next();
Comment 5 Brian de Alwis CLA 2010-03-12 09:11:03 EST
Yup, bug 304766 is a dupe: I saw the same NPEs on validation as reported by Leo after the initial CME.
Comment 6 Darin Wright CLA 2010-03-12 09:12:32 EST
*** Bug 304766 has been marked as a duplicate of this bug. ***
Comment 7 Leo Dos Santos CLA 2010-03-12 13:29:45 EST
(In reply to comment #4)
> I looked into the problem.   Fortunately it's a simple programming error rather
> than a race condition.
> 
> This problem is caused by a MANIFEST.MF header field with no value:

Same symptom, same cause. Nice find Brian!
Comment 8 Darin Wright CLA 2010-03-15 09:08:24 EDT
*** Bug 305845 has been marked as a duplicate of this bug. ***
Comment 9 Darin Wright CLA 2010-03-15 09:15:05 EDT
Looks like this was introduced by the fix to bug 303122
Comment 10 Darin Wright CLA 2010-03-15 16:31:08 EDT
Created attachment 162104 [details]
alternate patch
Comment 11 Darin Wright CLA 2010-03-15 16:32:49 EDT
Fixed. Please verify, Curtis.
Comment 12 Darin Wright CLA 2010-03-16 09:11:14 EDT
*** Bug 305969 has been marked as a duplicate of this bug. ***
Comment 13 Darin Wright CLA 2010-03-24 09:11:54 EDT
*** Bug 306930 has been marked as a duplicate of this bug. ***
Comment 14 Michael Rennie CLA 2012-05-16 09:53:39 EDT
*** Bug 308560 has been marked as a duplicate of this bug. ***