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

Bug 322804

Summary: ClassCastException adding an object to an EList with objects of a custom data type
Product: [Modeling] EMF Reporter: Eike Stepper <stepper>
Component: cdo.coreAssignee: Eike Stepper <stepper>
Status: CLOSED WORKSFORME QA Contact: Eike Stepper <stepper>
Severity: normal    
Priority: P3 CC: lindeman1966
Version: 4.0   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:

Description Eike Stepper CLA 2010-08-16 11:17:16 EDT
Cloned from: 322218: ClassCastException adding an object to an EList with objects of a custom data type
https://bugs.eclipse.org/bugs/show_bug.cgi?id=322218

I my model I have an attribute which is a list of int[], EList<int[]>. int[] is defined as a custom data type in the model. As soon as I try to add anything to the list I get a ClassCastException.

java.lang.ClassCastException: org.eclipse.emf.internal.cdo.revision.CDOListWithElementProxiesImpl cannot be cast to java.lang.String

ERROR    	at org.eclipse.emf.cdo.internal.common.model.CDOTypeImpl$25.convertToEMF(CDOTypeImpl.java:592)
	at org.eclipse.emf.internal.cdo.CDOStore.convertToEMF(CDOStore.java:581)
	at org.eclipse.emf.internal.cdo.CDOStore.get(CDOStore.java:176)
	at org.eclipse.emf.internal.cdo.CDOStore.isSet(CDOStore.java:194)
	at org.eclipse.emf.ecore.impl.EStoreEObjectImpl$BasicEStoreEList.isSet(EStoreEObjectImpl.java:161)
	at org.eclipse.emf.common.notify.impl.DelegatingNotifyingListImpl.addUnique(DelegatingNotifyingListImpl.java:280)
	at org.eclipse.emf.common.util.AbstractEList.add(AbstractEList.java:307)

I can also trigger the error calling "eIsSet" for the same attribute.
Comment 1 Eike Stepper CLA 2010-08-16 11:18:07 EDT
I added this to model5.ecore:

  <eClassifiers xsi:type="ecore:EClass" name="GenListOfIntArray">
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="elements" upperBound="-1"
        eType="#//IntArray"/>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EDataType" name="IntArray" instanceClassName="int[]"/>
Comment 2 Eike Stepper CLA 2010-08-16 11:24:38 EDT
I added Bugzilla_322804_Test:

  public void testAddElementToCustomTypedList() throws Exception
  {
    CDOSession session = openSession();
    CDOTransaction transaction = session.openTransaction();
    CDOResource resource = transaction.createResource("/r1");

    msg("Fill and commit a resource");
    GenListOfIntArray object = getModel5Factory().createGenListOfIntArray();
    resource.getContents().add(object);
    transaction.commit();

    msg("Add int[] elements");
    object.getElements().add(new int[] { 1, 2, 3, 4, 5 });
    object.getElements().add(new int[] { 10, 20, 30, 40, 50 });
    transaction.commit();
    session.close();
  }

Committed to HEAD
Comment 3 Eike Stepper CLA 2010-08-16 11:25:54 EDT
The test passes. Closing as WORKSFORME. Please reopen if you can reproduce the problem.
Comment 4 Eike Stepper CLA 2012-09-21 06:50:14 EDT
Closing.