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

Bug 509588

Summary: Concurrent Modification Exception when drag and dropping container mapping with contained elements.
Product: [Modeling] Sirius Reporter: Aurelien Didier <aurelien.didier51>
Component: DiagramAssignee: Project Inbox <sirius.diagram-inbox>
Status: CLOSED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: jessy.mallet, pierre-charles.david
Version: 4.1.1Keywords: triaged
Target Milestone: 5.0.0   
Hardware: PC   
OS: Windows NT   
See Also: https://git.eclipse.org/r/87823
https://git.eclipse.org/c/sirius/org.eclipse.sirius.git/commit/?id=ab5a1ccf93c3200b69cc4cc61b349383ae5e75b8
Whiteboard:
Attachments:
Description Flags
Sample projects to try to reproduce the issue none

Description Aurelien Didier CLA 2016-12-21 09:52:23 EST
Hello,

See: https://www.eclipse.org/forums/index.php?t=msg&th=1074546&goto=1722810&#msg_1722810

Concurrent Modification Exception occurs when I Drag and Drop my container mapping on the diagram element.

The problem is that the createDropinForContainerTask command is modifying the ownedDiagramElementsToDrop list during the iteration.
I don't know why this behavior appears only on certain case and works fine for others.

Maybe there are better corrections to do but the following one is working fine.

To solve this problem in Sirius DnDTasksOperations.moveSubNodes method, we can just create a new list and iterates on the new list, just like that:

Replace
        final EList<DDiagramElement> ownedDiagramElementsToDrop = oldDiagramElementContainer.getOwnedDiagramElements();

By
        ArrayList<DDiagramElement> ownedDiagramElementsToDrop = new ArrayList<DDiagramElement>(oldDiagramElementContainer.getOwnedDiagramElements());
        for (DDiagramElement diagramElementToDrop : ownedDiagramElementsToDrop ) {
               ***
        }

Regards,

Aurélien
Comment 1 Pierre-Charles David CLA 2016-12-30 05:17:32 EST
Created attachment 266078 [details]
Sample projects to try to reproduce the issue

The technical issue (and fix) seem obvious enough, but I was not able to actually reproduce the bug in practice from the information in the forum posts and initial bugzilla comment. I've attached my current partial attempt to reproduce the conditions for triggering the bug.

For reference, the original stack trace from the forum post:

Caused by: java.util.ConcurrentModificationException
	at org.eclipse.emf.common.util.AbstractEList$EIterator.checkModCount(AbstractEList.java:758)
	at org.eclipse.emf.common.util.AbstractEList$EIterator.doNext(AbstractEList.java:706)
	at org.eclipse.emf.common.util.AbstractEList$EIterator.next(AbstractEList.java:692)
	at org.eclipse.sirius.diagram.business.internal.helper.task.DnDTasksOperations.moveSubNodes(DnDTasksOperations.java:298)
	at org.eclipse.sirius.diagram.business.internal.helper.task.DropinForContainerTaskCommand.execute(DropinForContainerTaskCommand.java:103)
	at org.eclipse.sirius.business.api.helper.task.TaskExecutor.execute(TaskExecutor.java:64)
	at org.eclipse.sirius.tools.api.command.SiriusCommand.doExecute(SiriusCommand.java:80)
	at org.eclipse.emf.transaction.RecordingCommand.execute(RecordingCommand.java:135)
	at org.eclipse.emf.common.command.CompoundCommand.execute(CompoundCommand.java:261)
	at org.eclipse.sirius.diagram.ui.tools.api.command.GMFCommandWrapper.doExecuteWithResult(GMFCommandWrapper.java:102)
	at org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand.doExecute(AbstractTransactionalCommand.java:247)
	at org.eclipse.emf.workspace.AbstractEMFOperation.execute(AbstractEMFOperation.java:150)
	at org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy.execute(ICommandProxy.java:68)
	at org.eclipse.sirius.diagram.ui.graphical.edit.policies.SiriusContainerDropPolicy$1.execute(SiriusContainerDropPolicy.java:260)
	at org.eclipse.gmf.runtime.diagram.ui.commands.CommandProxy.doExecuteWithResult(CommandProxy.java:50)
	at org.eclipse.gmf.runtime.common.core.command.AbstractCommand.execute(AbstractCommand.java:134)
	at org.eclipse.sirius.diagram.ui.tools.internal.commands.WrappingCommandIgnoringAffectedFiles.execute(WrappingCommandIgnoringAffectedFiles.java:124)
	at org.eclipse.core.commands.operations.DefaultOperationHistory.execute(DefaultOperationHistory.java:516)
Comment 2 Pierre-Charles David CLA 2016-12-30 05:19:03 EST
Marking as triaged anyway, because the technical fix looks trivial and without risk.

Aurélien, if you have more details on how to tweak the attached project to trigger the bug, don't hesitate.
Comment 3 Eclipse Genie CLA 2016-12-30 05:21:23 EST
New Gerrit change created: https://git.eclipse.org/r/87823
Comment 5 Pierre-Charles David CLA 2017-02-01 10:55:56 EST
Fixed by ab5a1ccf93c3200b69cc4cc61b349383ae5e75b8. No automated test as we do not have a clear reproduction scenario, even manual, but the code change is trivial enough.
Comment 6 Jessy Mallet CLA 2017-05-18 12:21:09 EDT
Validated with Sirius 5.0.0.201705151305
Comment 7 Pierre-Charles David CLA 2017-05-19 03:10:09 EDT
Verified by Jessy.
Comment 8 Pierre-Charles David CLA 2017-06-29 03:33:07 EDT
Available in Sirius 5.0.0, see https://wiki.eclipse.org/Sirius/5.0.0 for details.