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: Elliotte Harold <elharo AT metalab.unc.edu>
  • To: Wolfgang Hoschek <whoschek AT lbl.gov>, xom-interest <xom-interest AT lists.ibiblio.org>
  • Cc:
  • Subject: Re: [XOM-interest] Unreachable block?
  • Date: Tue, 30 Nov 2004 04:35:51 -0500

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