-
Bug
-
Resolution: Fixed
-
P4
-
None
-
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
```
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
```
- csr for
-
JDK-8322132 One XMLStreamException constructor fails to initialize cause
- Closed