EcoreUtil.copy() throws Exception when copying recorded ChangeDescription [message #655544] |
Mon, 21 February 2011 12:38  |
Eclipse User |
|
|
|
Hello,
I am currently stuck at a problem regarding the copy method of the EcoreUtil class. I have recorded a ChangeDescription and want to store the description in both directions. Therefore I tried do to the following:
ChangeDescription cd1 = recorder.endRecording();
ChangeDescription cd2 = EcoreUtil.copy(cd1);
cd2.applyAndReverse()
This works fine for many cases but suddenly I ran into a case where sometimes(!) a Nullpointer Exception is thrown.
java.lang.NullPointerException
at org.eclipse.emf.ecore.change.impl.FeatureChangeImpl.getFeature(FeatureChangeImpl.java:286)
at org.eclipse.emf.ecore.change.impl.FeatureChangeImpl.basicGetReferenceValue(FeatureChangeImpl.java:383)
at org.eclipse.emf.ecore.change.impl.FeatureChangeImpl.setReferenceValue(FeatureChangeImpl.java:395)
at org.eclipse.emf.ecore.change.impl.FeatureChangeImpl.eSet(FeatureChangeImpl.java:717)
at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eSet(BasicEObjectImpl.java:1081)
at org.eclipse.emf.ecore.util.EcoreUtil$Copier.copyReference(EcoreUtil.java:769)
at org.eclipse.emf.ecore.util.EcoreUtil$Copier.copyReferences(EcoreUtil.java:646)
at org.eclipse.emf.ecore.util.EcoreUtil.copy(EcoreUtil.java:361)
I tried the whole day to figure out whats going on (EMF is really hard to debug) and I came to the conclusion that there is maybe a problem having objectsToAttach and a reference to it in the same ChangeDescription. Like the StateMarker Object which is referenced in line 17 (above featureName="world"). I did a lot of testing and figured out that the order, in which the EcoreUtil.Copier iterates over the elements, is important. But caused by the underlying Map, the order is not deterministic. Therefore copying of the ChangeDescription fails if the reference is copied before the StateMarker object.
The Exception is thrown because the eContainer() of the FeatureChange seems to be not set or at least eContainer().getTypedkey() is null, which is set after the object is added to the model.
<?xml version="1.0" encoding="UTF-8"?>
<change:ChangeDescription xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:change="http://www.eclipse.org/emf/2003/Change" xmlns:de.hpi.sam.dtrp.ontologies="http://basicontology/1.0">
<objectChanges>
<key href="data/worldchange/monitoring/initialstate/de.hpi.sam.dtrp.ontologies.barkeeper.OntologyWorld.xmi#a8916258-f492-4fa2-a2f4-55402c68e888"/>
<value featureName="artifactPool">
<listChanges kind="REMOVE" index="1"/>
</value>
</objectChanges>
<objectChanges>
<key href="data/worldchange/monitoring/initialstate/de.hpi.sam.dtrp.ontologies.barkeeper.OntologyWorld.xmi#/"/>
<value featureName="elements">
<listChanges index="2" referenceValues="a3802fee-2e18-4d2e-9f7c-589e48e97f1a"/>
<listChanges kind="REMOVE" index="4"/>
<listChanges kind="REMOVE" index="3"/>
</value>
</objectChanges>
<objectChanges key="a3802fee-2e18-4d2e-9f7c-589e48e97f1a">
<value featureName="world">
<referenceValue href="data/worldchange/monitoring/initialstate/de.hpi.sam.dtrp.ontologies.barkeeper.OntologyWorld.xmi#/"/>
</value>
</objectChanges>
<objectChanges>
<key href="data/worldchange/monitoring/initialstate/de.hpi.sam.dtrp.ontologies.barkeeper.OntologyWorld.xmi#8deb6746-abc3-45f4-b513-ba44654e1a76"/>
<value featureName="state" set="false"/>
</objectChanges>
<objectsToAttach xsi:type="de.hpi.sam.dtrp.ontologies:StateMarker" id="a3802fee-2e18-4d2e-9f7c-589e48e97f1a" state="guest_getBeer_hasMoney"/>
</change:ChangeDescription>
I appreciate any kind of help and thank you in advance!
Stefan
[Updated on: Mon, 21 February 2011 16:46] by Moderator
|
|
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03995 seconds