JDK packaged JAXP transformer indent no longer working in OpenJDK 11

Niels Bertram nielsbne at gmail.com
Tue May 7 23:45:25 UTC 2019

Hi JDK devs,

we recently started to upgrade from OpenJDK 8 to 11 and noticed that the
Xalan transformer shipped with the JDK is not handling whitespace
indentation properly anymore. Whilst it is not impacting the validity of
the XML produced, it is rather annoying that indented results now have
extra line breaks. E.g. we post-process some generated XSD files for
publication but when done in OpenJDK 11 they look horrible.

There are a few people seeing this issue:



It may be related to the changes made in this ticket:


Would it be possible for someone with permissions to raise a defect for

$ java -version
openjdk version "1.8.0_212"
OpenJDK Runtime Environment (build 1.8.0_212-8u212-b01-1~deb9u1-b01)
OpenJDK 64-Bit Server VM (build 25.212-b01, mixed mode)

(sources at the end of mail)

$ javac Transform.java

$ java Transform
<?xml version="1.0" encoding="UTF-8"?><books>
    <title>test book</title>

$ java Transform --indent
<?xml version="1.0" encoding="UTF-8"?><books>
    <title>test book</title>

$ java -version
openjdk version "11.0.3" 2019-04-16
OpenJDK Runtime Environment (build 11.0.3+1-Debian-1bpo91)
OpenJDK 64-Bit Server VM (build 11.0.3+1-Debian-1bpo91, mixed mode, sharing)

$ java Transform
<?xml version="1.0" encoding="UTF-8"?><books>
    <title>test book</title>

$ $ java -Djaxp.debug=1 Transform --indent
JAXP: find factoryId =javax.xml.transform.TransformerFactory
JAXP: loaded from fallback value:
JAXP: created new instance of class
com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl using
ClassLoader: null
<?xml version="1.0" encoding="UTF-8"?><books>


        <title>test book</title>



Source for Transform.java


import javax.xml.transform.OutputKeys;
import javax.xml.transform.Templates;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import java.io.ByteArrayInputStream;
import java.io.StringWriter;
import java.nio.charset.StandardCharsets;

public class Transform {

  public static void main(String[] args) {

    try {

      boolean indent = args != null && args.length == 1 &&

      String template = "<xsl:stylesheet version=\"1.0\" xmlns:xsl=\"
http://www.w3.org/1999/XSL/Transform\">\n" +
        "  <xsl:template match=\"@*|node()\">\n" +
        "    <xsl:copy>\n" +
        "      <xsl:apply-templates select=\"@*|node()\"/>\n" +
        "    </xsl:copy>\n" +
        "  </xsl:template>\n" +

      String input = "<books>\n" +
        "  <book>\n" +
        "    <title>test book</title>\n" +
        "  </book>\n" +

      Templates xsl = TransformerFactory.newInstance()
        .newTemplates(new StreamSource(new

      final StringWriter result = new StringWriter();

      Transformer transformer = xsl.newTransformer();

      // as soon as we configure auto-indent the output
      transformer.setOutputProperty(OutputKeys.INDENT, indent ? "yes" :

      transformer.transform(new StreamSource(new
ByteArrayInputStream(input.getBytes(StandardCharsets.UTF_8))), new

    } catch (Exception e) {



More information about the jdk-dev mailing list