[jdom-interest] How to "crash" JDOM, part 1

David W. Smiley dsmiley at mitre.org
Thu Aug 31 11:13:48 PDT 2000

> After thinking about this a little more, I suspect we may
> be making
> things harder than they need to be. Given the existing constraint
> that you
> can't add an Element that already has a parent, I can't see any
> way that
> it's possible for an Element to have a pointer to any of its
> ancestors in
> its content list. The only degenerate case I can see is
> "element.addContent(element)" on a newly created Element, which
> can be
> solved with a simple check for self-reference in addition to the
> check for a
> null parent. Did I miss a case?

	Yes.  What if you have some big tree and you add the rootElement to one
of the leaves.  This is the other extreme of your self-reference
example; your case is when the rootElement is the leaf.  This has
nothing to do with whether docRootElement is true or false.
	BTW, to make getRootElement() faster, I'd do it with iteration, not
recursion since it'll be faster; my example was just pseuodocode anyway.

-- David Smiley

More information about the jdom-interest mailing list