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

DOM Serializer prints stack traces to System.err

XMLWordPrintable

        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

              aefimov Aleksej Efimov
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Created:
                Updated:
                Resolved: