Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » EcoreUtil.copy() throws Exception when copying recorded ChangeDescription
EcoreUtil.copy() throws Exception when copying recorded ChangeDescription [message #655544] Mon, 21 February 2011 17:38 Go to next message
No real name is currently offline No real nameFriend
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 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: EcoreUtil.copy() throws Exception when copying recorded ChangeDescribtion [message #655601 is a reply to message #655592] Mon, 21 February 2011 21:44 Go to previous messageGo to next message
No real name is currently offline No real nameFriend
Messages: 5
Registered: February 2011
Junior Member
Thank you for your quick answer! Sadly the special copying behavior seems to be not the problem. I have already read about that and checked it. The exception is thrown while cd1 is copied by the EcoreUtil.Copier. Therefore it is not possible to compare the two objects if the error appears.
Re: EcoreUtil.copy() throws Exception when copying recorded ChangeDescribtion [message #655687 is a reply to message #655601] Tue, 22 February 2011 10:06 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30554
Registered: July 2009
Senior Member
Which version of EMF are you using? I think this was fixed...


dershao@dershao.de wrote:
> Thank you for your quick answer! Sadly the special copying behavior
> seems to be not the problem. I have already read about that and
> checked it. The exception is thrown while cd1 is copied by the
> EcoreUtil.Copier. Therefore it is not possible to compare the two
> objects if the error appears.
Re: EcoreUtil.copy() throws Exception when copying recorded ChangeDescribtion [message #655719 is a reply to message #655687] Tue, 22 February 2011 12:39 Go to previous messageGo to next message
No real name is currently offline No real nameFriend
Messages: 5
Registered: February 2011
Junior Member
I am using the following jars:

org.eclipse.emf.ecore_2.6.1.v20100914-1218.jar
org.eclipse.emf.ecore.change_2.5.1.v20100907-1643.jar

If you have further information like a bugreport or something similar please share this. Thank you!




Re: EcoreUtil.copy() throws Exception when copying recorded ChangeDescribtion [message #655879 is a reply to message #655719] Wed, 23 February 2011 00:48 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30554
Registered: July 2009
Senior Member
I think is was fixed by 315753.


dershao@dershao.de wrote:
> I am using the following jars:
>
> org.eclipse.emf.ecore_2.6.1.v20100914-1218.jar
> org.eclipse.emf.ecore.change_2.5.1.v20100907-1643.jar
>
> If you have further information like a bugreport or something similar
> please share this. Thank you!
>
>
>
>
>
Re: EcoreUtil.copy() throws Exception when copying recorded ChangeDescribtion [message #655924 is a reply to message #655879] Wed, 23 February 2011 10:34 Go to previous messageGo to next message
No real name is currently offline No real nameFriend
Messages: 5
Registered: February 2011
Junior Member
if have replaced the change jar with the most current stable version (org.eclipse.emf.ecore.change_2.7.0.v20110120-0110.jar) and now it is finally working.

Thank you very much Ed - you saved my day!
Re: EcoreUtil.copy() throws Exception when copying recorded ChangeDescribtion [message #658215 is a reply to message #655924] Mon, 07 March 2011 12:48 Go to previous messageGo to next message
anand.yashwanth is currently offline anand.yashwanthFriend
Messages: 1
Registered: March 2011
Junior Member
Hi,

I am also hitting the same issue when i upgraded to latest Helios with EMF version. I have version as org.eclipse.emf.ecore.change_2.5.1.v20100907-1643.jar. When i try to update only this plugin to 2.7.0 . i get dependecies missing issue. Can you please tell me what else you did to get this fixed?
Re: EcoreUtil.copy() throws Exception when copying recorded ChangeDescription [message #658227 is a reply to message #655544] Mon, 07 March 2011 13:57 Go to previous message
No real name is currently offline No real nameFriend
Messages: 5
Registered: February 2011
Junior Member
I did not update the whole eclipse plugin. Instead I added both jar-libs in my project as a regular dependency.
Previous Topic:[Teneo/EclipseLink]Entity class [class model.impl.BookImpl] has no primary key specified
Next Topic:EMF model file
Goto Forum:
  


Current Time: Tue Oct 22 11:55:16 GMT 2019

Powered by FUDForum. Page generated in 0.02776 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top