[jdom-interest] detach() [eg]

Kenworthy, Edward edward.kenworthy at exchange.co.uk
Sun Apr 22 23:39:52 PDT 2001

-----Original Message-----
From: Joseph Bowbeer [mailto:jozart at csi.com]
Sent: 20 April 2001 23:06
To: jdom-interest at jdom.org
Subject: [jdom-interest] detach() [eg]

edward.kenworthy at exchange.co.uk writes:

> The argument is that you're hiding a user error.
> Never, ever, a good idea.

+Well, there's good and bad on all sides.  That's why +they pay us.  (Oh,
+that's right: We're volunteers...)


+1. Second-guessing the user is not a good idea either.  +For example, what
+makes us think the user intended to setRootElement +before they setDocType?

Second guessing the user is what you are doing if the document fixes itself
up when you remove the root element. So I guess we both agree that's bad.

+What if the user puts the wrong kind of Element in the +Document, or
+constructs invalid Elements?  These are all errors that +JDOM has no clue
+about, and are therefore the client's responsibility.  +Compared to this,
+checking for a null root is a cinch.

Completely different kind of error. Fraud by analogy ;-)

+2. Adding artificial state to a class (the Document in +this case) is not a
+good idea either.  It makes the class harder to +understand and less

It's not artifical. In one case you explicitly show its an invalid state, in
the other you add a dummy, worse than worthless, root element which you have
to go and explicitly parse for to see if it is erroneous (and then hope that
no valid root element could ever have the same value as the auto-added

+So as to fail fast, I suggest that we only consider +throwing illegal-state
+if someone tries to set a document property that depends +on the root
+being set.  Are there any such properties?

Yes. Most of them. And the argument is not "invalid state "versus
"no-invalid state" it's between the "explicit invalid state" where an
exception is thrown and "masked invalid state" where the document fixes
itself(!) with some dummy data.

+3. Finally, looking at the XMLOutputter example, I don't +see any benefit
+from IllegalStateException.

So how would you detect that you screwed-up and destroyed your document ?

+Let's say the user detaches the rootElement and then +passes the Document
+XMLOutputter.  Now, unless XMLOutputter checks its +arguments, the Document
+is going to throw an IllegalStateException when +XMLOutputter tries to
+it.  I propose that XMLOutputter throw an +IllegalArgument Exception

That's insane. So the *document* is in an illegal state but the
XMLOutputter, passed a valid argument (a document) throws an illegalargument
exception ? That's just silly.

+Joe Bowbeer


To control your jdom-interest membership:

More information about the jdom-interest mailing list