Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6889654

SAXParseException should have a better toString method

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 1.4.0
    • 6u14
    • xml
    • h1180
    • generic
    • generic
    • Verified

      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.

            joehw Joe Wang
            kkawagucsunw Kohsuke Kawaguchi (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: