[CDO 4.2] ConcurrentModificationException in native with EAllContents() while not in legacy [message #1051803] |
Mon, 29 April 2013 08:35 |
Eclipse User |
|
|
|
Hi CDO Team,
We have and we use some code which iterates through a call to
eAllContents() and in this iteration we modify the model on which we do
iteration. I understand that it is a bad use of iterator because the
model must not be changed during iteration, but this works fine in
legacy while in native it throws a ConcurrentModificationException. And
like we have several snippets of code which do that we would like to
have this code works in native like in legacy. I have attached a junit
test based on CDO test framework to show the native/legacy difference.
Best Regards.
/*
* Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Esteban Dugueperoux - initial API and implementation
*/
package org.eclipse.emf.cdo.tests.bugzilla;
import org.eclipse.emf.cdo.tests.AbstractCDOTest;
import org.eclipse.emf.cdo.tests.model3.Model3Factory;
import org.eclipse.emf.cdo.tests.model3.NodeA;
import org.eclipse.emf.ecore.EObject;
import java.util.Iterator;
/**
* @author Esteban Dugueperoux
*/
public class Bugzilla_440XXX_Test extends AbstractCDOTest
{
@CleanRepositoriesBefore
public void testEAllContents() throws Exception
{
NodeA nodeA1 = Model3Factory.eINSTANCE.createNodeA();
NodeA nodeA2 = Model3Factory.eINSTANCE.createNodeA();
nodeA2.setName("nodeA2");
NodeA nodeA3 = Model3Factory.eINSTANCE.createNodeA();
NodeA nodeA4 = Model3Factory.eINSTANCE.createNodeA();
nodeA1.getChildren().add(nodeA2);
nodeA2.getChildren().add(nodeA3);
Iterator<EObject> eAllContents = nodeA1.eAllContents();
while (eAllContents.hasNext())
{
EObject next = eAllContents.next();
if (next instanceof NodeA)
{
NodeA nodeA = (NodeA)next;
if ("nodeA2".equals(nodeA.getName()))
{
nodeA.getChildren().add(nodeA4);
}
}
}
}
}
|
|
|
|
Powered by
FUDForum. Page generated in 0.03919 seconds