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

SAXException needs to be JDK 1.4 friendly

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Duplicate
    • Icon: P3 P3
    • tbd
    • 5.0
    • xml

      SAXException doesn't work very nicely with JDK 1.4 exception chaining mechanism.

      1. It doesn't implement the getCause() method, so it doesn't print the nested exception nicely in 1.4 and later.

      SOLUTION:
         add the getCasue() method as follows:
         
         Throwable getCause() {
           return exception;
         }

         This is 1.3-safe; this code will still runs in JDK 1.3 and earlier, yet with JDK 1.4 or later it can
         participate in the exception chaining correctly.

      2. The current implementation of SAXException.toString() looks like this:

          public String toString ()
          {
      if (exception != null) {
      return exception.toString();
      } else {
      return super.toString();
      }
          }

         and therefore when there is a nested exception (which is the norm), then it clobbers the detail message provided by
         the SAXException itself.

      SOLUTION:
         This "toString" method should be just deleted. Exception chaining is the correct way
         of displaying information about the nested exception.

      3. SAXParseException doesn't print the location information.
         None of the SAXParseException methods print out the location information. When exceptions are nested, this makes
         it impossible to see where the error occured, which is a criticial piece of information.

      SOLUTION;
         Implement the toString() method in such a way that it returns getMessage() as well as the location information.
         With this change, e.printStackTrace() will be able to print the location information, even if SAXParseException
         is nested within other exceptions.

            Unassigned Unassigned
            kkawagucsunw Kohsuke Kawaguchi (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: