[jdom-interest] detach() [eg]
Joseph Bowbeer
jozart at csi.com
Sat Apr 28 16:38:33 PDT 2001
jh writes:
> I would argue if a document without a root is passed to this
> method, it's a programmer error, appropriate for an ISE.
Yes, it's a programmer error, but surely IllegalArgumentException relates
more closely to the Consumer class and the invoked consume method than an
IllegalStateException coming from within the Document.
> The code for a move:
>
> if (elt.isRootElement()) {
> elt.getDocument().setRootElement(new Element("Bogus"));
> } else {
> elt.detach();
> }
> newelt.addContent(elt);
>
> Not much better, and again many programmers will just write:
>
> newelt.addContent(elt.detach());
>
In the examples you give for detaching an Element, you always include the
state checks (isRootElement) -- as if (re)moving a root is a perfectly
normal thing to do. Yet, you argue that consumers of Document don't need to
check the state of the Document because removing the root from a Document is
a special case and not part of the normal flow of control. Why is this a
reasonable disparity?
--
Joe Bowbeer
More information about the jdom-interest
mailing list