JDK-6857903 : SAXException.initCause() does not correctly set Exception
  • Type: Bug
  • Component: xml
  • Sub-Component: org.xml.sax
  • Affected Version: 6u14
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2009-07-07
  • Updated: 2018-03-07
  • Resolved: 2018-02-09
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 11
11 b01Fixed
Related Reports
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.6.0_14"
Java(TM) SE Runtime Environment (build 1.6.0_14-b08)
Java HotSpot(TM) Client VM (build 14.0-b16, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]

A DESCRIPTION OF THE PROBLEM :
Upgrading to this release has caused the following code to fail:

        Exception cause = new Exception();
        SAXException e = new SAXException("A SAX exception");
        e.initCause(cause);
        System.out.println(cause == e.getCause());

Using 6u14 this now prints "false" because initCause(Throwable t); is not overriden in SAXException.

Taking a step back though, why do you need to store the Exception in SAXException? Why can you not simply delegate all calls to Throwable? I see no logic that SAXException adds on top of Throwable, it just provides a getException() method.

It seems it last worked under:

Java version "1.6.0_13"
Java(TM) SE Runtime Environment (build 1.6.0_13-b03)
Java HotSpot(TM) Client VM (build 11.3-b02, mixed mode)

I've also tried a few other earlier ones (1.6.0_11, 1.6.0_06, 1.5.0_17)

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Exception cause = new Exception();
        SAXException e = new SAXException("A SAX exception");
        e.initCause(cause);
        System.out.println(cause == e.getCause());

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Should output: "true"
ACTUAL -
outputs "false"

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import org.xml.sax.SAXException;


public class Test {

     public static void main(String[] args) {
        Exception cause = new Exception();
        SAXException e = new SAXException("A SAX exception");
        e.initCause(cause);
        System.out.println(cause == e.getCause());
    }

}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Do not use the initCause();

Release Regression From : 6u13
The above release value was the last known release where this 
bug was not reproducible. Since then there has been a regression.

Comments
The fix is simpler then JDK-8034556, because this bug can be fixed without serial form change (as it was done by JDK-8034556). The following fix solves the reported issue keeping the serial form intact: @@ -94,7 +94,7 @@ */ public SAXException (Exception e) { - super(); + super(e); this.exception = e; } @@ -152,7 +152,7 @@ * @return Return the cause of the exception */ public Throwable getCause() { - return exception; + return super.getCause(); }
20-12-2017

Hi Aleksej, Would you want to apply a fix similar to JDK-8034556? Thanks.
31-03-2017

Looks similar to this one bug: JDK-8034556
08-10-2014