EcoreUtil.copy() throws Exception when copying recorded ChangeDescription [message #655544] |
Mon, 21 February 2011 17:38 |
No real name Messages: 5 Registered: February 2011 |
Junior Member |
|
|
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 21:46] Report message to a moderator
|
|
|
Re: EcoreUtil.copy() throws Exception when copying recorded ChangeDescribtion [message #655592 is a reply to message #655544] |
Mon, 21 February 2011 20:38 |
Eclipse User |
|
|
|
Originally posted by: c.krause.cwi.nl
Hi Stefan,
what I know is that EcoreUtil.copy() not nessesarily gives you a 100%
identical copy of your model. If you have bidirectional references to
some non-contained object, EcoreUtil.copy() will not copy that
reference, because this would change the original model.
Maybe you can check whether cd2 is really identical with cd1.
Cheers,
Christian
On 02/21/11 18:38, dershao@dershao.de wrote:
> Hello,
>
> I'm currently stuck at a problem regarding the copy method of the
> Ecoreutil class. If 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.getFeatu re(FeatureChangeImpl.java:286)
>
> at
> org.eclipse.emf.ecore.change.impl.FeatureChangeImpl.basicGet ReferenceValue(FeatureChangeImpl.java:383)
>
> at
> org.eclipse.emf.ecore.change.impl.FeatureChangeImpl.setRefer enceValue(FeatureChangeImpl.java:395)
>
> at
> org.eclipse.emf.ecore.change.impl.FeatureChangeImpl.eSet(Fea tureChangeImpl.java:717)
>
> at
> org.eclipse.emf.ecore.impl.BasicEObjectImpl.eSet(BasicEObjec tImpl.java:1081)
>
> at
> org.eclipse.emf.ecore.util.EcoreUtil$Copier.copyReference(Ec oreUtil.java:769)
>
> at
> org.eclipse.emf.ecore.util.EcoreUtil$Copier.copyReferences(E coreUtil.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 may be 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() fails 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.ont ologies.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.ont ologies.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.ont ologies.barkeeper.OntologyWorld.xmi#/ "/>
>
> </value>
> </objectChanges>
> <objectChanges>
> <key
> href=" data/worldchange/monitoring/initialstate/de.hpi.sam.dtrp.ont ologies.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
|
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.06018 seconds