JDK-6889654 : SAXParseException should have a better toString method
  • Type: Bug
  • Component: xml
  • Sub-Component: org.xml.sax
  • Affected Version: 6u14
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2009-10-08
  • Updated: 2012-04-25
  • Resolved: 2009-10-23
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
1.4.0 h1180Fixed
Description
SAXParseException retains a very useful information regarding where the error occurred, yet this information is not displayed unless the caller specifically looks for SAXParseException and prints it. This is especially problematic when SAXParseException shows up in a nested exception of an exception chaining.

To fix this, SAXParseException should implement the toString() method that returns a reasonable String representation of all the information that it holds. Something like:

    public String toString() {
        StringBuilder buf = new StringBuilder(getClass().getName());
        String message = getLocalizedMessage();
        if (message!=null)     buf.append(": ").append(message);
        if (publicId!=null)    buf.append(":publicId=").append(publicId);
        if (systemId!=null)    buf.append(":systemId=").append(publicId);
        if (lineNumber!=-1)    buf.append(":lineNumber=").append(lineNumber);
        if (columnNumber!=-1)  buf.append(":columnNumber=").append(columnNumber);
        return buf.toString();
    }

This change doesn't affect the signature, so the spec revision is not necessary.

Comments
EVALUATION ChangeSet=http://hg.openjdk.java.net/jdk6/jdk6/jaxp/rev/5c070921580c,ChangeRequest=6923146,ChangeRequest=6917454,ChangeRequest=6472982,ChangeRequest=6909759,ChangeRequest=6333993,ChangeRequest=6900779,ChangeRequest=6900773,ChangeRequest=6900249,ChangeRequest=6675332,ChangeRequest=6889654,ChangeRequest=6889649,ChangeRequest=6863312
18-02-2010

EVALUATION Suggested fix has been added with a slight change in the format since the original message was a complete sentence itself.
23-10-2009