JDK-8011795 : DOM Serializer prints stack traces to System.err
  • Type: Bug
  • Component: xml
  • Sub-Component: org.w3c.dom
  • Affected Version: 7
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2013-04-04
  • Updated: 2014-11-17
  • Resolved: 2014-05-13
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 7 JDK 8
7u76Fixed 8u20 b15Fixed
Description
FULL PRODUCT VERSION :
java version  " 1.7.0_09 " 
Java(TM) SE Runtime Environment (build 1.7.0_09-b05)
Java HotSpot(TM) 64-Bit Server VM (build 23.5-b02, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Linux myhost 2.6.32-279.5.2.el6.x86_64 #1 SMP Fri Aug 24 01:07:11 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux

Microsoft Windows [Version 6.1.7601]

A DESCRIPTION OF THE PROBLEM :
DOM Serializer prints stack traces to System.err when underlying output stream throws IOException.

REGRESSION.  Last worked in version 7

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile and run test case provided below.




EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Expect the following output in System.err:

Exception
ACTUAL -
java.io.IOException
at DOMSerializerBugReproduction$1.write(DOMSerializerBugReproduction.java:26)
at java.io.OutputStream.write(OutputStream.java:116)
at sun.nio.cs.StreamEncoder.writeBytes(StreamEncoder.java:221)
at sun.nio.cs.StreamEncoder.implFlushBuffer(StreamEncoder.java:291)
at sun.nio.cs.StreamEncoder.implFlush(StreamEncoder.java:295)
at sun.nio.cs.StreamEncoder.flush(StreamEncoder.java:141)
at java.io.OutputStreamWriter.flush(OutputStreamWriter.java:229)
at com.sun.org.apache.xml.internal.serialize.Printer.flush(Printer.java:324)
at com.sun.org.apache.xml.internal.serialize.XMLSerializer.serializeElement(XMLSerializer.java:1092)
at com.sun.org.apache.xml.internal.serialize.BaseMarkupSerializer.serializeNode(BaseMarkupSerializer.java:1193)
at com.sun.org.apache.xml.internal.serialize.BaseMarkupSerializer.serializeNode(BaseMarkupSerializer.java:1268)
at com.sun.org.apache.xml.internal.serialize.BaseMarkupSerializer.serialize(BaseMarkupSerializer.java:471)
at com.sun.org.apache.xml.internal.serialize.DOMSerializerImpl.write(DOMSerializerImpl.java:808)
at DOMSerializerBugReproduction.main(DOMSerializerBugReproduction.java:33)
Exception


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.io.IOException;
import java.io.OutputStream;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.ls.DOMImplementationLS;
import org.w3c.dom.ls.LSOutput;
import org.w3c.dom.ls.LSSerializer;

public class DOMSerializerBugReproduction {

    public static void main(String[] args) {
        try {
            DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
            Document document = documentBuilder.newDocument();
            Element root = document.createElement( " test " );
            document.appendChild(root);
            OutputStream out = new OutputStream() {
                @Override
                public void write(int b) throws IOException {
                    throw new IOException();
                }
            };
            DOMImplementationLS implementation = (DOMImplementationLS) document.getImplementation();
            LSOutput lsOutput = implementation.createLSOutput();
            lsOutput.setByteStream(out);
            LSSerializer lsSerializer = implementation.createLSSerializer();
            lsSerializer.write(document, lsOutput);
            out.flush();
        } catch (Exception e) {
            System.err.println( " Exception " );
        }
    }
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
doesn't exist
Comments
This one bug was resolved in JDK9 as part of Xerces update project JDK-8035437 bug. The following line was removed and actually it's not needed because the stack trace information are filled in during LSException construction: src/com/sun/org/apache/xerces/internal/serialize/DOMSerializerImpl.java: - e.printStackTrace(); throw (LSException) DOMUtil.createLSException(LSException.SERIALIZE_ERR, e).fillInStackTrace(); The following change needs to be introduced to JDK8 and 7.
12-05-2014

While working on JDK-8035437, could you also take a look at this one? Thanks.
05-05-2014