Skip to Content.
Sympa Menu

xom-interest - Re: [XOM-interest] Unreachable block?

xom-interest AT lists.ibiblio.org

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: Wolfgang Hoschek <whoschek AT lbl.gov>
  • To: Elliotte Harold <elharo AT metalab.unc.edu>
  • Cc: xom-interest <xom-interest AT lists.ibiblio.org>
  • Subject: Re: [XOM-interest] Unreachable block?
  • Date: Tue, 30 Nov 2004 13:20:27 -0800

I see. However, it seems you can reformulate the check as follows

else if (this.getParent() != null && child.getChildCount() > 0 && isCycle(child, this.getParent())) {
throw new CycleException(
"Cannot add an ancestor as a child");
}

Now building a tree bottom-up this.getParent() == null and there should be now difference to top down building.
Wolfgang.

On Nov 30, 2004, at 1:35 AM, Elliotte Harold wrote:

Wolfgang Hoschek wrote:

Can anyone give an example situation where
throw new CycleException(
"Cannot add an ancestor as a child");
is reachable in the method below? I can't see how it could theoretically be reached, given that child.getParent() != null has already been tested, and it's only for cases where child.isElement? An ancestor always has getParent != null, otherwise it can't be an ancestor in the first place. If it is indeed unreachable, the whole block


This one came up because someone did it in their code, and I wrote a unit test to prove it. See http://www.xom.nu/clover_html/nu/xom/Element.html
Note the 100% test coverage for Element.java including the referenced line. I believe it's tested by ParentNodeTest.testCycle:

public void testCycle() {

Element a = new Element("test");
Element b = new Element("test");
try {
a.appendChild(b);
b.appendChild(a);
fail("Allowed cycle");
}
catch (CycleException success) {
assertNotNull(success.getMessage());
}

}

--
Elliotte Rusty Harold elharo AT metalab.unc.edu
XML in a Nutshell 3rd Edition Just Published!
http://www.cafeconleche.org/books/xian3/
http://www.amazon.com/exec/obidos/ISBN=0596007647/cafeaulaitA/ref=nosim





Archive powered by MHonArc 2.6.24.

Top of Page