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

One XMLStreamException constructor fails to initialize cause

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 23
    • None
    • xml
    • None
    • b04
    • generic
    • generic

      The class XMLStreamException has three constructors taking a Throwable cause:

      XMLStreamException(Throwable th)
      XMLStreamException(String msg, Throwable th)
      XMLStreamException(String msg, Location location, Throwable th)

      The first two correctly pass the Throwable parameter to the superclass constructor, thereby initializing the chained exception cause.

      However, the third constructor does not.

      Here's a reproducer:

      ```
      import javax.xml.stream.*;
      public class XMLStreamExceptionTest {
          public static void main(String[] args) {
              Throwable cause = new Throwable("test cause");

              // Create exception #1
              XMLStreamException e1 = new XMLStreamException(cause);
              System.out.println("Cause #1: " + e1.getCause());

              // Create exception #2
              XMLStreamException e2 = new XMLStreamException("test 2", cause);
              System.out.println("Cause #2: " + e1.getCause());

              // Create exception #3
              Location location = new Location() {
                  public int getLineNumber() { return 0; }
                  public int getColumnNumber() { return 0; }
                  public int getCharacterOffset() { return 0; }
                  public String getPublicId() { return null; }
                  public String getSystemId() { return null; }
              };
              XMLStreamException e3 = new XMLStreamException("test 1", location, cause);
              System.out.println("Cause #3: " + e3.getCause());
          }
      }
      ```

      Expected output:

      ```
      Cause #1: java.lang.Throwable: test cause
      Cause #2: java.lang.Throwable: test cause
      Cause #3: java.lang.Throwable: test cause
      ```

      Actual output:
      ```
      Cause #1: java.lang.Throwable: test cause
      Cause #2: java.lang.Throwable: test cause
      Cause #3: null
      ```

            acobbs Archie Cobbs
            acobbs Archie Cobbs
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: