-
Bug
-
Resolution: Fixed
-
P3
-
11, 17
-
b01
-
b28
-
Not verified
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8269060 | 18 | Joe Wang | P3 | Resolved | Fixed | b03 |
JDK-8270599 | 17.0.1 | Joe Wang | P3 | Resolved | Fixed | b03 |
ADDITIONAL SYSTEM INFORMATION :
Tested it on MacOSX (Open Adopt JDK) and windows 10 (https://jdk.java.net/ and Open Adopt JDK)
A DESCRIPTION OF THE PROBLEM :
When switching from Java 8 (Oracle) to Java 11 (AdoptOpenJDK) the indentation of our XML has been changed.
The indentation fails when a xml element is defined with an attribute xml:space=preserve. Everything after the xml element containing the attribute is no longer indented
REGRESSION : Last worked in version 8u281
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
With the below code the problem can be reproduced. The variable data must be a XML string, for instance
<?xml version=\"1.0\" encoding=\"UTF-8\"?><a><b>650b4d21</b><c>If true</c><d xml:space=\"preserve\">TRUE</d><e>test</e></a>
In this case the tags 'a','b','c','d' are indented, everything after tag 'd' will not be indented.
Transformer transformer = TransformerFactory.newInstance("com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl", Test.class.getClassLoader());
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
transformer.setOutputProperty(OutputKeys.CDATA_SECTION_ELEMENTS, "body hyperlink");
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
StringWriter writer = new StringWriter();
StreamSource in = new StreamSource(new StringReader(data));
transformer.transform(in, new StreamResult(writer));
System.out.println("-----");
System.out.println(writer.toString());
System.out.println("-----");
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<a>
<b>650b4d21</b>
<c>If true</c>
<d xml:space=\"preserve\">TRUE</d>
<e>test</e>
</a>
ACTUAL -
<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<a>
<b>650b4d21</b>
<c>If true</c>
<d xml:space=\"preserve\">TRUE</d><e>test</e></a>
FREQUENCY : always
Tested it on MacOSX (Open Adopt JDK) and windows 10 (https://jdk.java.net/ and Open Adopt JDK)
A DESCRIPTION OF THE PROBLEM :
When switching from Java 8 (Oracle) to Java 11 (AdoptOpenJDK) the indentation of our XML has been changed.
The indentation fails when a xml element is defined with an attribute xml:space=preserve. Everything after the xml element containing the attribute is no longer indented
REGRESSION : Last worked in version 8u281
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
With the below code the problem can be reproduced. The variable data must be a XML string, for instance
<?xml version=\"1.0\" encoding=\"UTF-8\"?><a><b>650b4d21</b><c>If true</c><d xml:space=\"preserve\">TRUE</d><e>test</e></a>
In this case the tags 'a','b','c','d' are indented, everything after tag 'd' will not be indented.
Transformer transformer = TransformerFactory.newInstance("com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl", Test.class.getClassLoader());
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
transformer.setOutputProperty(OutputKeys.CDATA_SECTION_ELEMENTS, "body hyperlink");
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
StringWriter writer = new StringWriter();
StreamSource in = new StreamSource(new StringReader(data));
transformer.transform(in, new StreamResult(writer));
System.out.println("-----");
System.out.println(writer.toString());
System.out.println("-----");
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<a>
<b>650b4d21</b>
<c>If true</c>
<d xml:space=\"preserve\">TRUE</d>
<e>test</e>
</a>
ACTUAL -
<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<a>
<b>650b4d21</b>
<c>If true</c>
<d xml:space=\"preserve\">TRUE</d><e>test</e></a>
FREQUENCY : always
- backported by
-
JDK-8269060 XML transformation and indentation when using xml:space
- Resolved
-
JDK-8270599 XML transformation and indentation when using xml:space
- Resolved
- relates to
-
JDK-8301568 XML indentation regression after JDK-8265073
- Open