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

trebor.a.rude at lmco.com trebor.a.rude at lmco.com
Wed Aug 30 10:02:44 PDT 2000


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.

> -----Original Message-----
> From:	Jason Hunter [SMTP:jhunter at collab.net]
> Sent:	Wednesday, August 30, 2000 10:46 AM
> To:	trebor.a.rude at lmco.com
> Cc:	aleksi.kallio at infomates.net; jdom-interest at jdom.org
> Subject:	Re: [jdom-interest] How to "crash" JDOM, part 1
> 
> trebor.a.rude at lmco.com wrote:
> > 
> > The problem here isn't getCopy(), it's that he added the copy as 
> > a child of itself, which shouldn't be allowed.
> 
> You can add a copy of an element as a child to itself.  Not a shallow
> copy, but a deep copy, and this is (at least supposed to be) a deep
> copy.
> 
>    a
>   / \
>  b   c
> 
> becomes
> 
>    a
>   / \  \
>  b   c  a
>        / \
>       b   c
> 
> -jh-



More information about the jdom-interest mailing list