JDK-8230083 : Transform with indent moves tabs to new lines
  • Type: Bug
  • Component: xml
  • Sub-Component: javax.xml.transform
  • Affected Version: 11.0.4
  • Priority: P3
  • Status: Closed
  • Resolution: Incomplete
  • OS: generic
  • CPU: generic
  • Submitted: 2019-08-22
  • Updated: 2023-10-18
  • Resolved: 2019-08-23
Related Reports
Duplicate :  
Description
A DESCRIPTION OF THE PROBLEM :
In Java 11 (and probably all 9+) calling transform with a xml with \t in it and OutputKeys.INDENT enabled moves the \t to new lines making the result broken.

REGRESSION : Last worked in version 8u221

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Use java 11
Create transformer with property OutputKeys.INDENT set to "yes"
Set transformer property "{http://xml.apache.org/xslt}indent-amount" to "2"
Transform an xml that is already indented with \t characters

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
XML is prettified, readable without empty new lines.
ACTUAL -
New lines are added for \t characters creating a bloated XML.

---------- BEGIN SOURCE ----------
    @Test
    public void pretty_format_with_tabs() throws TransformerException {
        String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" +
                "<document>\n" +
                "\t<test>\n" +
                "\t\t12345\n" +
                "\t</test>\n" +
                "</document>";

        String expectedResult = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><document>\n" +
                "  <test>12345</test>\n" +
                "</document>\n";

        javax.xml.transform.TransformerFactory transformerFactory = TransformerFactory.newInstance();
        javax.xml.transform.Transformer transformer = transformerFactory.newTransformer();
        transformer.setOutputProperty(javax.xml.transform.OutputKeys.INDENT, "yes");
        transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", String.valueOf(2));

        javax.xml.transform.Source in = new StreamSource(new StringReader(xml));
        javax.xml.transform.stream.StreamResult out = new StreamResult(new StringWriter());
        transformer.transform(in, out);
        String result = out.getWriter().toString();

        assertEquals(expectedResult, result);
    }
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Trimming each string row before transformation removes the tabs.

FREQUENCY : always



Comments
The output of the test case is same from JDK 8u221 until JDK 14-ea. So, requested submitter for further details and inputs to determine if the issue is a regression.
23-08-2019