JDK-6710741 : DOMSerializerImpl.writeToString swallows nested exceptions
  • Type: Bug
  • Component: xml
  • Sub-Component: org.w3c.dom
  • Affected Version: 5.0
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: linux
  • CPU: x86
  • Submitted: 2008-06-04
  • Updated: 2012-04-25
  • Resolved: 2009-06-18
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.
Other JDK 6 JDK 7
1.3.0 1.3Fixed 6u18Fixed 7Fixed
Description
com.sun.org.apache.xml.internal.serialize.DOMSerializerImpl.writeToString(Node) has code like this:

try {
  // ...
} catch (RuntimeException e) {
  // ...
  throw new LSException(LSException.SERIALIZE_ERR, e.toString());
} catch (IOException ioe) {
  // ...
  throw new DOMException(DOMException.DOMSTRING_SIZE_ERR, msg);
}

If there is a failure from some implementation-internal code, the stack trace will be lost.

Observed because prepareForSerialization can throw NPE in

  next = node.getNextSibling();

which I will report separately if I can figure out under which conditions it occurs.

Observed in JDK 5 but JDK 7 seems to still have the same code.

Comments
EVALUATION We've decided to fix this specific case since it affected NetBeans development. For all other cases, I've created a new request. See 6852393. This is now fixed in jaxp 1.3, 1.4. Integrations into jdk5/6/7 will follow.
18-06-2009

EVALUATION Several exception classes in the JAXP API swallow cause in the same way as indicated in this report. Because it involves API changes, we should consider this in future release, e.g. jaxp 1.5.
16-06-2009

SUGGESTED FIX Always use Throwable.initCause() when rethrowing an exception as a different type.
04-06-2008