# Bug in RM builder? (getParent) + Incomplete Common IM spec? **Category:** [Reference Implementation: Java (archive)](https://discourse.openehr.org/c/reference-implementation-java-archive/154) **Created:** 2007-01-18 16:52 UTC **Views:** 5 **Replies:** 4 **URL:** https://discourse.openehr.org/t/bug-in-rm-builder-getparent-incomplete-common-im-spec/14618 --- ## Post #1 by @erik.sundvall Hi Rong\! \(\+Tom\) Mattias mentioned that the two of you \(MF\+RC\) had chatted about the issue that the parent is set null instead of the real parent in the AOM by the parser\. I now had a look at the RMObjectBuilder and found a similar issue\. Is it not so that RM objects that inherit from Locatable should know \(have a reference to or be able to look up\) their parent if they have one \(i\.e all non root objects\)? A question to Tom: Why is parent optional \(0\.\.1\) in the spec, is it only because root nodes don't have parents or is it because parent can be ignored by implementations? Maybe some text and possibly an invariant statement in the spec could make this more clear? I guess the RMObjectBuilder should be the right place to attach children and parents? If you add the two code lines below to the end of the method testBuildComposition\(\) in the unit test class org\.openehr\.build\.EHRBuildTest you will find the error by the last test\.   assertEquals\("section", section\(\), composition\.getContent\(\)\.get\(0\)\); //passes fine   assertEquals\("parent", composition, composition\.getContent\(\)\.get\(0\)\.getParent\(\)\); //fails I might have misunderstood things here, but I guess that one in addition to constructors has to use the protected setter setParent\(\) \(inherited from Locatable\) during the build process\. This also brings me to the question if the current java\-ref\-impl implementation strives for strong or weak immutability? See strong/weak differences here: http://www.javaworld.com/javaworld/javaqa/2002-12/01-qa-1206-immutable.html \(continues\) http://www.javaworld.com/javaworld/javaqa/2002-12/01-qa-1206-immutable.html?page=2 and http://www.javaranch.com/newsletter/Apr2003/immutable.htm \(middle of page\) The reason I ask is that we are experimenting with mutable/immutable class pairs and converters\. Best regards, Erik Sundvall http://www.imt.liu.se/~erisu/ --- ## Post #2 by @thomas.beale Erik Sundvall wrote: > Hi Rong\! \(\+Tom\) > > Mattias mentioned that the two of you \(MF\+RC\) had chatted about the > issue that the parent is set null instead of the real parent in the > AOM by the parser\. I now had a look at the RMObjectBuilder and found a > similar issue\. Is it not so that RM objects that inherit from > Locatable should know \(have a reference to or be able to look up\) > their parent if they have one \(i\.e all non root objects\)? > > A question to Tom: > Why is parent optional \(0\.\.1\) in the spec, is it only because root > nodes don't have parents or is it because parent can be ignored by >   it's mainly because of the reason being discussed elsewhere \- it cannot usually be sensibly supplied on creation\. > implementations? Maybe some text and possibly an invariant statement > in the spec could make this more clear? >   \- thomas --- ## Post #3 by @system > Hi Rong! (+Tom) > > Mattias mentioned that the two of you (MF+RC) had chatted about the > issue that the parent is set null instead of the real parent in the Yes, now I think I will go for no "parent" in the constructor + addChild() solution (thanks for the tip, Tom). > AOM by the parser. I now had a look at the RMObjectBuilder and found a > similar issue. Is it not so that RM objects that inherit from > Locatable should know (have a reference to or be able to look up) > their parent if they have one (i.e all non root objects)? > > A question to Tom: > Why is parent optional (0..1) in the spec, is it only because root > nodes don't have parents or is it because parent can be ignored by > implementations? Maybe some text and possibly an invariant statement > in the spec could make this more clear? > > I guess the RMObjectBuilder should be the right place to attach > children and parents? > If you add the two code lines below to the end of the method > testBuildComposition() in the unit test class > org.openehr.build.EHRBuildTest you will find the error by the last > test. > > assertEquals("section", section(), composition.getContent().get(0)); > //passes fine > assertEquals("parent", composition, > composition.getContent().get(0).getParent()); //fails Thanks for reporting this. It will be on the to-do list. Right now, updating the AOM and the parser; the work on rm-builder will start later preferably with input on common kernel API. > I might have misunderstood things here, but I guess that one in > addition to constructors has to use the protected setter setParent() > (inherited from Locatable) during the build process. > > This also brings me to the question if the current java-ref-impl > implementation strives for strong or weak immutability? For RM/AOM, both I guess depends on the context. > See strong/weak differences here: > [http://www.javaworld.com/javaworld/javaqa/2002-12/01-qa-1206-immutable.html](http://www.javaworld.com/javaworld/javaqa/2002-12/01-qa-1206-immutable.html) > (continues) > [http://www.javaworld.com/javaworld/javaqa/2002-12/01-qa-1206-immutable.html?page=2](http://www.javaworld.com/javaworld/javaqa/2002-12/01-qa-1206-immutable.html?page=2) > and > [http://www.javaranch.com/newsletter/Apr2003/immutable.htm](http://www.javaranch.com/newsletter/Apr2003/immutable.htm) (middle of page) > > The reason I ask is that we are experimenting with mutable/immutable > class pairs and converters. Look forward to your result on this. :) /Rong --- ## Post #4 by @erik.sundvall Could you \(Tom or Rong\) explain this \(the content of addChild etc\) further or point to some explaining text on the net? Best regards, Erik Sundvall http://www.imt.liu.se/~erisu/ --- ## Post #5 by @system Check this out [http://my.openehr.org/wsvn/ref_impl_eiffel/TRUNK/libraries/openehr/src/am/archetype/constraint_model/c_attribute.e?op=file&rev=0&sc=0](http://my.openehr.org/wsvn/ref_impl_eiffel/TRUNK/libraries/openehr/src/am/archetype/constraint_model/c_attribute.e?op=file&rev=0&sc=0) /Rong --- **Canonical:** https://discourse.openehr.org/t/bug-in-rm-builder-getparent-incomplete-common-im-spec/14618 **Original content:** https://discourse.openehr.org/t/bug-in-rm-builder-getparent-incomplete-common-im-spec/14618