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

Bug 320571

Summary: ConcurrentModificationException when modifying artifact names
Product: [Technology] Tigerstripe Reporter: Navid Mehregani <nmehrega>
Component: UIAssignee: Navid Mehregani <nmehrega>
Status: RESOLVED FIXED QA Contact:
Severity: major    
Priority: P3 CC: erdillon
Version: unspecified   
Target Milestone: 0.5M0   
Hardware: PC   
OS: Mac OS X - Carbon (unsup.)   
Whiteboard:
Attachments:
Description Flags
Patch none

Description Navid Mehregani CLA 2010-07-21 19:13:28 EDT
Build Identifier: 

None of the structures under AbstractArtifact.java are protected against concurrent access.  Under ArtifactRenameRequest.java the following code in updateReferences method modifies a Collection while iterating over it.  This obviously causes a ConcurrentModificationException, which in turn causes the EMF transaction to fail.  Once the transaction fails, EMF tries to rollback the transaction by recovering the old name, hence the renaming is never successful. 

Note that this only happens with contained artifacts and JRE doesn't always guarantee ConcurrentModificationException to be thrown.

ArtifactRenameRequest#updateReferences():

// take care of contained artifacts same way
// This is looking DOWNWARDS
Collection<IModelComponent> contains =  artifact						.getContainedModelComponents();
boolean containsChanged = false;
for (IModelComponent cont : contains) {
   if (cont instanceof AbstractArtifact) {
	AbstractArtifact containedArt = (AbstractArtifact) cont;
	if (containedArt.getFullyQualifiedName().equals(oldFQN)							|| containedArt.getFullyQualifiedName().equals(									newName)) {
							   aArtifact.removeContainedModelComponent(cont);
aArtifact							.addContainedModelComponent(referencedArtifact);
	needSave = false;
    }
  }
}


Reproducible: Always

Steps to Reproduce:
1. Create a new class diagram
2. Create two entities with an association between them
3. Double click on the association
4. Rename the association in the edit dialog that pops up and click on OK.

If AbstractArtifact is in fact accessed on multiple threads, then we need to protect this class under concurrent access.  Otherwise, we can fix the code snippet that I've indicated under Details section.
Comment 1 Eric Dillon CLA 2010-08-09 21:57:28 EDT
because all the renames from diagrams should be hooked up with the refactor framework it should be possible to rename an association by clicking on its name. The refactor dialog should pop up. To be verified.

Also, as a result of other fix, the "name" box should now be disabled on this dialog. so this should not happen directly anymore.

Still this code WILL be called from the initial rename (when DnD from palette), which is worth a fix.
Comment 2 Navid Mehregani CLA 2010-08-19 10:18:30 EDT
Created attachment 176998 [details]
Patch

Fixed the ConcurrentModificationException in ArtifactRenameRequest
Comment 3 Navid Mehregani CLA 2010-08-24 12:15:42 EDT
Submitted patch.