Skip to Content.
Sympa Menu

xom-interest - [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: xom-interest AT lists.ibiblio.org
  • Subject: [XOM-interest] Unreachable block?
  • Date: Mon, 29 Nov 2004 19:20:52 -0800

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

else if (child.getChildCount() > 0 && isCycle(child, this)) {

can be removed without changing any semantics.
Wolfgang.


Element.java:
void insertionAllowed(Node child, int position) {

if (child == null) {
throw new NullPointerException(
"Tried to insert a null child in the tree");
}
else if (child.getParent() != null) {
throw new MultipleParentException(child.toString()
+ " child already has a parent.");
}
else if (child.isElement()) {
if (child == this) {
throw new CycleException(
"Cannot add a node to itself");
}
else if (child.getChildCount() > 0 && isCycle(child, this)) {
throw new CycleException(
"Cannot add an ancestor as a child");
}
return;
}
else if (child.isText()
|| child.isProcessingInstruction()
|| child.isComment()) {
return;
}
else {
throw new IllegalAddException("Cannot add a "
+ child.getClass().getName() + " to an Element.");
}

}





Archive powered by MHonArc 2.6.24.

Top of Page