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

JDK7 update 4 changed XML indenting behavior

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 7
    • xml
    • x86
    • linux_ubuntu

      FULL PRODUCT VERSION :
      $ ~/dev/tools/jdk1.7.0_03/bin/java -version
      java version "1.7.0_03"
      Java(TM) SE Runtime Environment (build 1.7.0_03-b04)
      Java HotSpot(TM) 64-Bit Server VM (build 22.1-b02, mixed mode)

      $ ~/dev/tools/jdk1.7.0_04/bin/java -version
      java version "1.7.0_04"
      Java(TM) SE Runtime Environment (build 1.7.0_04-b20)
      Java HotSpot(TM) 64-Bit Server VM (build 23.0-b21, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Linux work-laptop 3.0.0-17-generic #30-Ubuntu SMP Thu Mar 8 20:45:39 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux

      A DESCRIPTION OF THE PROBLEM :
      Between JDK7 update 3 and update 4, the output traditional "pretty printing" of XML has changed. In update 3 and prior (including JDK6 and earlier), there's a line separator after the XML prolog. As of update 4, the XML prolog and starting root element are on the same line.

      A full example:

      $ cat XmlTest.java
      import javax.xml.transform.*;
      import javax.xml.transform.stream.*;
      import java.io.*;

      public class XmlTest {
          public static void main(String[] args) throws Exception {
              Transformer transformer = TransformerFactory.newInstance().newTransformer();
              transformer.setOutputProperty(OutputKeys.INDENT, "yes");
              transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
              StreamResult result = new StreamResult(System.out);
              transformer.transform(new StreamSource(new StringReader("<foo/>")), result);
          }
      }

      $ javac XmlTest.java

      $ ~/dev/tools/jdk1.7.0_03/bin/java XmlTest
      <?xml version="1.0" encoding="UTF-8"?>
      <foo/>

      $ ~/dev/tools/jdk1.7.0_04/bin/java XmlTest
      <?xml version="1.0" encoding="UTF-8"?><foo/>

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile the provided source code and run it with 7u3 and 7u4.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The same output from both versions.
      ACTUAL -
      Missing line separator in 7u4 output.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import javax.xml.transform.*;
      import javax.xml.transform.stream.*;
      import java.io.*;

      public class XmlTest {
          public static void main(String[] args) throws Exception {
              Transformer transformer = TransformerFactory.newInstance().newTransformer();
              transformer.setOutputProperty(OutputKeys.INDENT, "yes");
              transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
              StreamResult result = new StreamResult(System.out);
              transformer.transform(new StreamSource(new StringReader("<foo/>")), result);
          }
      }

      ---------- END SOURCE ----------

            joehw Joe Wang
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: