United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6889654 SAXParseException should have a better toString method
JDK-6889654 : SAXParseException should have a better toString method

Details
Type:
Bug
Submit Date:
2009-10-08
Status:
Closed
Updated Date:
2012-04-25
Project Name:
JDK
Resolved Date:
2009-10-23
Component:
xml
OS:
generic
Sub-Component:
org.xml.sax
CPU:
generic
Priority:
P3
Resolution:
Fixed
Affected Versions:
6u14
Fixed Versions:
1.4.0 (h1180)

Related Reports

Sub Tasks

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

Suggested fix has been added with a slight change in the format since the original message was a complete sentence itself.
                                     
2009-10-23
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
                                     
2010-02-18



Hardware and Software, Engineered to Work Together