[jdom-interest] detach() [eg]
jozart at csi.com
Thu Apr 26 01:30:36 PDT 2001
> I suspect IllegalStateException was intended for situations
> where thread issues could leave an object in an illegal state;
> e.g. a thread finished half an update before it was interrupted.
I agree with Elliotte that adding ISE to Document is an uncomfortable
Having a "getter" method throw an ISE is not very bean-like. Users expect
"getter" methods to work without exception or side-effects. Introspection
is based on this contract.
While there are some "getters" that throw ISE, such as getWriter() and
getOutputStream() in the servlet API, these methods are producing a value,
not simply fetching a property. These "getters" have no associated
"setters", and they are understood to be active methods, with documented
side-effects. (With URL connections, even the order in which the getters
are called is important.)
None of the description above applies documents. The way I see it, the root
is a property of the document, and a property has a value, or is null.
By the way, have we seen real code samples where an ISE would actually help?
A code snippet or two might shed some light on this.
I agree with Patrick that the "root" of the problem is that Element.detach
can operate implicitly on the Document's rootElement property. If we
prevent elt.detach() from operating on a root element, then we prevent the
dangerous side-effects. As long as we provide an explicit way for the
programmer to remove/replace the rootElement of the Document, then it
probably matters less to us that the Document's rootElement might be null --
because the programmer did it explicitly.
More information about the jdom-interest