JDK-6296446 : REGRESSION: Java 5 transformer doesn't indent
  • Type: Bug
  • Component: xml
  • Sub-Component: javax.xml.transform
  • Affected Version: 5.0
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2005-07-13
  • Updated: 2012-04-25
  • Resolved: 2005-08-03
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
5.0u6 b07Fixed
Description
FULL PRODUCT VERSION :

C:\jdk1.5.0_04\bin>.\java -version
java version "1.5.0_04"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_04-b05)
Java HotSpot(TM) Client VM (build 1.5.0_04-b05, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]

A DESCRIPTION OF THE PROBLEM :
Java 5 transformer does not honor the indenting request:

    tf.setOutputProperty(OutputKeys.INDENT, "yes");
    tf.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");


REGRESSION.  Last worked in version jwsdp-1.4

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile and run the supplied sources under
java 1.4.1_02 and java 1.5.0_04.
Java 4 will indent, java 5 will not.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
<?xml version="1.0" encoding="UTF-8"?>
<one>
    <two>
        <three>Am I indented?</three>
    </two>
</one>
ACTUAL -
<?xml version="1.0" encoding="UTF-8"?>
<one>
<two>
<three>Am I indented?</three>
</two>
</one>

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.io.*;
import javax.xml.parsers.*;
import javax.xml.transform.*;
import javax.xml.transform.dom.*;
import javax.xml.transform.stream.*;
import org.w3c.dom.*;
import org.xml.sax.*;

public class IndentTest
{
	public static void printXML(String xmlStr_in)
	{
		try
		{
			DocumentBuilderFactory factory =
					DocumentBuilderFactory.newInstance();
			DocumentBuilder builder = factory.newDocumentBuilder();

			StringReader strRdr = new StringReader(xmlStr_in);
			InputSource in = new InputSource(strRdr);

			Document doc = builder.parse(in);

			Transformer tf = TransformerFactory.newInstance().newTransformer();


			tf.setOutputProperty(OutputKeys.INDENT, "yes");
			tf.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");

			tf.transform(new DOMSource(doc), new StreamResult(System.out));

		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
	}

	// java 1.4.1_02: output is indented
	//<?xml version="1.0" encoding="UTF-8"?>
	//<one>
	//    <two>
	//        <three>Am I indented?</three>
	//    </two>
	//</one>

	// java 1.5.0_04: output is not indented:
	//<?xml version="1.0" encoding="UTF-8"?>
	//<one>
	//<two>
	//<three>Am I indented?</three>
	//</two>
	//</one>

	public static void main(String[] args_in)
	{
		printXML("<one><two><three>Am I indented?</three></two></one>");
		System.exit(0);
	}
}


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

Release Regression From : 1.4.2
The above release value was the last known release where this 
bug was known to work. Since then there has been a regression.
###@###.### 2005-07-13 18:10:18 GMT

Comments
EVALUATION added indent number to the translet and serialization handler which was missing initially
27-07-2005