[jdom-interest] detach() [eg]

Jason Hunter jhunter at collab.net
Mon Apr 23 22:25:36 PDT 2001

Joseph Bowbeer wrote:
> I'm for either:
> (1) Allow the root element to be detached by allowing documents to have a
> null root.  Assign the burden of checking for a null root to the client.
> (Part of the client's precondition.)

I don't like that one at all.  Burden should be removed from the client
wherever possible.  Why burden the masses if we can burden the few?  :-)

> (2) Prevent the root element from being detached.

That seems like well-formedness getting in the way.  Up til now
well-formedness has been a Good Thing and on any violation I expect the
user would say, "Oh, thanks."  Like making an element with a space in
it, or adding an elt as a child of itself.  This is the first time a
well-formedness check would have the user say, "Damn, just do what I

> No one likes placeholder (3), except perhaps as the lesser of evils.


> As for IllegalStateException (4), I don't like it because of its time bomb
> nature.  Compared to a null root, IllegalStateException makes it harder for
> clients to determine the state of a given document (calling getRootElement
> would throw an IllegalStateException, right?), and it gives the clients no
> discretion in determining whether an empty document is in fact a legal
> argument or not.

Almost no one would ever see the ISE.  Only if you detached a root and
then later actually cared about the doc.  I find that unlikely.  I'm
sure people could write in many use cases for detaching the root, but
none of them would care about the document afterward.  It's throw-away. 
So we let the root leave the document, and we put up a warning flag in
case someone tries to use the doc later.  I've been convinced a warning
flag is better than an internal sweep-it-under-the-rug.


More information about the jdom-interest mailing list