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

No newline emitted after XML decl in XSLT output

    Details

    • Subcomponent:
    • Resolved In Build:
      b18
    • CPU:
      x86
    • OS:
      linux, linux_ubuntu
    • Verification:
      Verified

      Description

      Test program:

      ---%<---
      import java.io.StringReader;
      import javax.xml.parsers.DocumentBuilderFactory;
      import javax.xml.transform.OutputKeys;
      import javax.xml.transform.Result;
      import javax.xml.transform.Source;
      import javax.xml.transform.Transformer;
      import javax.xml.transform.TransformerFactory;
      import javax.xml.transform.dom.DOMSource;
      import javax.xml.transform.stream.StreamResult;
      import javax.xml.transform.stream.StreamSource;
      import org.w3c.dom.Document;
      import org.xml.sax.InputSource;
      public class JAXP7u4Regression {
          public static void main(String[] args) throws Exception {
              String data =
                  "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
                  "<r>\n" +
                  " <e/>\n" +
                  "</r>\n";
              Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(new StringReader(data)));
              TransformerFactory tf = TransformerFactory.newInstance();
              String IDENTITY_XSLT_WITH_INDENT = // #5064280 workaround
                  "<xsl:stylesheet version='1.0' " +
                  "xmlns:xsl='http://www.w3.org/1999/XSL/Transform&#39; " +
                  "xmlns:xalan='http://xml.apache.org/xslt&#39; " +
                  "exclude-result-prefixes='xalan'>" +
                  "<xsl:output method='xml' indent='yes' xalan:indent-amount='4'/>" +
                  "<xsl:template match='@*|node()'>" +
                  "<xsl:copy>" +
                  "<xsl:apply-templates select='@*|node()'/>" +
                  "</xsl:copy>" +
                  "</xsl:template>" +
                  "</xsl:stylesheet>";
              Transformer t = tf.newTransformer(new StreamSource(new StringReader(IDENTITY_XSLT_WITH_INDENT)));
              t.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
              Source source = new DOMSource(doc);
              Result result = new StreamResult(System.out);
              t.transform(source, result);
          }
          private JAXP7u4Regression() {}
      }
      ---%<---

      Output in 7u3 (b04; Ubuntu, 32-bit JVM):

      <?xml version="1.0" encoding="UTF-8"?>
      <r>
          <e/>
      </r>

      vs. 7u4 (b14):

      <?xml version="1.0" encoding="UTF-8"?><r>
          <e/>
      </r>

      Note the missing newline between the XML declaration and the root element.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                joehw Joe Wang
                Reporter:
                jglick Jesse Glick (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: