Skip to Content.
Sympa Menu

xom-interest - [XOM-interest] Node hierarchy does not prevent cycles

xom-interest AT lists.ibiblio.org

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: "McEniry, Michael" <mmceniry AT itsc.uah.edu>
  • To: <xom-interest AT lists.ibiblio.org>
  • Subject: [XOM-interest] Node hierarchy does not prevent cycles
  • Date: Fri, 12 Sep 2003 13:29:51 -0500

The node hierarchy does not prevent cycles
(aka "I'm my own grandpa").

The simplest example is:

Element a = new Element("a");
a.appendChild(a);
// time passes...
a.toXML(); // causes a StackOverflowError

In my case, it was a dumb typo, but the error appears
far away from the typo, and I consumed what few sanity
points I had left tracking this down.

Should ParentNode.insertChild(Node child, int position)
climb its own parent tree looking for child?

...
for (ParentNode parent = this;
parent != null;
parent = parent.getParent()) {
if (parent == child) {
throw new SomeException("cyclic hierarchy");
}
}
...

Has this been discussed before? If so, please,
point me there. Thanks.




Archive powered by MHonArc 2.6.24.

Top of Page