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

Jason Hunter jhunter at collab.net
Wed Aug 30 15:05:46 PDT 2000


trebor.a.rude at lmco.com wrote:
> 
> So this should work:
> 
> Element foo = new Element(foo);
> Element bar = foo.getCopy("bar");
> foo.addContent(bar);
> 
> But that isn't what happened in the first case, what happened 
> amounts to this:
> 
> bar.addContent(bar);
> 
> So bar adds a pointer to itself in its content list, which causes the
> infinite loop when trying to traverse the tree in XMLOutputter, and 
> that's what shouldn't be allowed: adding a pointer to yourself to 
> your children. It won't fully prevent loops, but it should help.

Like I said, if the getCopy() isn't doing a full clone then that's a bug
and you should feel free to roll up your sleeves and figure it out.

I think you're right there's another issue that the bar.addContent(bar)
command could cause a corrupted tree if bar doesn't have a parent.  We
have logic that an element with an existing parent can't be added to
another element (you must remove it from its original parent first) but
an element just hovering there could theoretically be added to itself,
or to its grandchild or great-grandchild or even its child's child's
child's child.  Eliminating the possibility of a loop would require a
logic as part of every add that looked at the merge point and walks up
the tree to the root making sure you never find yourself in the process.

-jh-





More information about the jdom-interest mailing list