Murtaza,

This is just a standard Java programming issue. You can't remove objects 
in a List while you have an active Iterator, unless you use 
Iterator.remove().

In your example, instead of this:

       department_A.detach();

you would need to call:

      iter.remove();
 
to remove the department from the list and inform the Iterator of the 
change.

Frank


"Murtaza Goga" <[EMAIL PROTECTED]> wrote on 03/20/2007 11:24:34 
AM:

> We have two disconnected DataGraphs and when we add DataObjects from one
> DataGraph into the other (with or without 'detach' being called) we are
> observe ConcurrentModificationExceptions.  I have pasted a simple test
> case below which adds a 'department' from one company into another.
> This test case will error out with the above exception.  The company.xsd
> is from the Tuscany M3 RC1 build.
> 
> 
> 
> Can someone explain this behavior and what should be the recommended
> usage pattern?
> 
> 
> 
>   /**
> 
>    * @see junit.framework.TestCase#setUp()
> 
>    */
> 
>   @Override
> 
>   protected void setUp() throws Exception {
> 
>     XSDHelper.INSTANCE.define(ClassLoader
> 
>         .getSystemResourceAsStream("company.xsd"), null);
> 
>   }
> 
> 
> 
>   /**
> 
>    * Test list usage.
> 
>    */
> 
>   public void test01Concurrency() {
> 
>     DataGraph dataGraph_A = createCompanyDataGraph(1);
> 
>     DataGraph dataGraph_B = createCompanyDataGraph(1);
> 
> 
> 
>     List departments_A =
> dataGraph_A.getRootObject().getList("departments");
> 
>     List departments_B =
> dataGraph_B.getRootObject().getList("departments");
> 
>     for (Iterator iter = departments_A.iterator(); iter.hasNext();) {
> 
>       DataObject department_A = (DataObject) iter.next();
> 
>       department_A.detach(); // Does not matter if this call is made or
> not
> 
>       departments_B.add(department_A);
> 
>     }
> 
>   }
> 
> 
> 
>   /**
> 
>    * Creates the company datagraph.
> 
>    * @param departmentsToCreate the number of departments to create.
> 
>    * @return the DataGraph.
> 
>    */
> 
>   private DataGraph createCompanyDataGraph(int departmentsToCreate) {
> 
>     DataGraph dataGraph = SDOUtil.createDataGraph();
> 
>     dataGraph.createRootObject("company.xsd", "CompanyType");
> 
>     for (int i = 0; i < departmentsToCreate; i++) {
> 
>       dataGraph.getRootObject().createDataObject("departments",
> "company.xsd",
> 
>           "DepartmentType");
> 
>     }
> 
>     return dataGraph;
> 
>   }
> 
> 
> 
> Thanks,
> 
> Murtaza.
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to