Changing SAX?

Volume 9, Issue 22; 23 Feb 2006; last modified 08 Oct 2010

Yesterday, the question was XHTML™ Modularization 1.1, today it's SAX.

Apropos of the question “how many changes can be introduced into a document without subjecting it to technical review”, can I make a really, really small change to SAX?

The problem is the following bug report:

SAXException can take a nested exception, but it doesn't implement the getCause method, so it doesn't participate in the exception nesting mechanism introduced in JDK 1.4.

Because of this, when one prints out "e.printStackTrace()", it doesn't show exceptions nested inside SAXException.

The proposed fix is straightforward, simply add:

public Throwable getCause() {
  return exception;
}

to org.xml.sax.SAXException. I don't believe that this introduces any compatibility problems. Under JDK 1.4 and beyond, getCause is already inherited from Throwable and I don't think the extra method will cause any problems under JDK 1.3 and earlier (but I could be wrong about that, I haven't really investigated it and I don't claim to be a master of JDK compatibility rules by any means).

That said, as the specification lead for JAXP, I'm very reluctant to introduce any changes into the endorsed API, no matter how small, without community support.

The submitter opines, “I understand the hesitation. On the other hand, people are wasting their time because we don't have these three lines.” I understand that too.

At least there's somewhere I can ask. I have exactly the same problem with another specification, except without that luxury.

I just hope consensus builds quickly because the window for making this change for JAXP 1.4 is really, really small.

Comments

I wonder if it's also worth a look at the somewhat misguidedly overridden toString() method in SAXException, which has tripped me up from time to time. This example class shows how wrapping an exception in a SAXException can produce a mangled stack trace, containing the class name and message from the nested exception, but the stack trace of the SAXException.

I realise a comment in your blog is hardly the best place to report this problem. I intended to write a comment to the effect of "it would be nice if SAXException didn't produce broken stack traces", but then I realised I couldn't remember exactly how it was broken, so I ended up firing up Eclipse to get my head around the problem again. Is that mailing list you linked to the best place to ask, or is this a known issue that would be redundant?

—Posted by Adam Fitzpatrick on 27 Feb 2006 @ 08:30 UTC #