[jdom-interest] non-deterministic behaviour [eg]

Joseph Bowbeer jozart at csi.com
Wed Apr 11 16:31:28 PDT 2001

I like Josh Bloch's rule of thumb: Strive to make the API "failure atomic"
with respect to checked exceptions, and document when it isn't.

However, the IllegalAddException thrown by setMixedContent is not a checked
exception.  It extends IllegalArgumentException, and it signifies a
programmer error that is not in general recoverable, so I don't think we
should go to great lengths to recover from it.

My initial reaction was to make setMixedContent failure atomic, but I didn't
realize at the time that IllegalAddException was an unchecked exception.  I
also didn't notice the interaction between setMixedContent and the other
overridable methods.

Notice that setMixedContent dispatches to other overridable methods.  Can we
know beforehand whether these methods will throw an exception?  If not, how
can we restore the Element subclass to its previous state when an exception
is thrown?  Is reinstating the old content list enough, or is the subclass
maintaining additional state?  A prepare-commit protocol is one solution to
this kind of problem, but that's clearly over doing it.

Is it a big problem if setMixedContent is *not* failure atomic?

I'm going to follow up with more messages about tweaking the JDOM API for
subclassing.  For example, we should refrain from calling overridable
methods in constructors, clone(), and readObject().  Stuff like that.  More

Joe Bowbeer

More information about the jdom-interest mailing list