-
Bug
-
Resolution: Fixed
-
P5
-
1.1.3, 1.2.0, 1.4.1
-
b16
-
generic
-
generic
-
Verified
Name: eaR10174 Date: 10/17/2001
The sample test.java (See below) shows that neither SAXTransformerFactory nor
Transformer use the org.xml.sax.helpers.XMLReaderFactory.createXMLReader() method to
create XMLReader for javax.xml.transform.sax.SAXSource object which is not initialized
with reader. But the spec reads :
"public SAXSource(InputSource inputSource)
...
The Transformer or SAXTransformerFactory creates a reader via XMLReaderFactory (if
setXMLReader is not used), sets itself as the reader's ContentHandler, and calls
reader.parse(inputSource)."
Analyzing test failure we found that the implemetations of SAXTransformerFactory and
Transformer don't conform to the javadoc specification. They try first to create the
reader via the javax.xml.parsers.SAXParser and only after failure of that attempt the
XMLReaderFactory is used.
This bug is found in the builds jdk1.4.0-beta3-b83, jaxp-1.1.3 and affects a new JCK1.4
test
api/javax_xml/transform/sax/SAXSource/index.html#Ctor[Ctor003]
------------------------------------test.java-----------------------------
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParserFactory;
import javax.xml.transform.sax.SAXSource;
import javax.xml.transform.sax.SAXTransformerFactory;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.stream.StreamResult;
import org.xml.sax.InputSource;
import org.xml.sax.helpers.XMLFilterImpl;
import org.xml.sax.SAXException;
import java.io.StringReader;
import java.io.StringWriter;
public class test {
public static class ReaderStub extends XMLFilterImpl {
static boolean created = false;
public ReaderStub() throws ParserConfigurationException, SAXException {
super();
super.setParent(SAXParserFactory.newInstance().newSAXParser().getXMLReader());
created = true;
}
}
public static void main (String[] args) {
/* Set own XMLReader instead of default */
System.setProperty("org.xml.sax.driver", ReaderStub.class.getName());
System.out.println("Start testing SAXTransformerFactory...");
testSAXTransformerFactory();
System.out.println("Finished testing SAXTransformerFactory...\n ");
System.out.println("Start testing Transformer...");
testTransformer();
System.out.println("Finished testing Transformer...\n ");
}
private static void testTransformer() {
String xml = "<?xml version='1.0'?><root/>";
ReaderStub.created = false;
try {
TransformerFactory transFactory = TransformerFactory.newInstance();
Transformer transformer = transFactory.newTransformer();
InputSource in = new InputSource(new StringReader(xml));
SAXSource source = new SAXSource(in);
StreamResult result = new StreamResult(new StringWriter());
transformer.transform(source, result);
printWasReaderStubCreated();
} catch (TransformerException e) {
System.out.println(e);
}
}
private static void testSAXTransformerFactory() {
String xsl = "<?xml version='1.0'?>\n"
+ "<xsl:stylesheet"
+ " xmlns:xsl='http://www.w3.org/1999/XSL/Transform'"
+ " version='1.0'>\n"
+ " <xsl:template match='/'>Hello World!</xsl:template>\n"
+ "</xsl:stylesheet>\n";
ReaderStub.created = false;
try {
TransformerFactory transFactory = TransformerFactory.newInstance();
if (transFactory.getFeature(SAXTransformerFactory.FEATURE) == false) {
System.out.println("SAXTransformerFactory not supported");
return;
}
InputSource in = new InputSource(new StringReader(xsl));
SAXSource source = new SAXSource(in);
transFactory.newTransformer(source);
printWasReaderStubCreated();
} catch (TransformerException e) {
System.out.println(e);
}
}
private static void printWasReaderStubCreated() {
if (ReaderStub.created) {
System.out.println("\tReaderStub is created.");
} else {
System.out.println("\tReaderStub is not created.");
}
}
}
---------------------------------------------------------------------------
--------------------- test output -----------------------------------------
% java -showversion test
java version "1.4.0-beta3"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta3-b83)
Java HotSpot(TM) Client VM (build 1.4.0-beta3-b83, mixed mode)
Start testing SAXTransformerFactory...
ReaderStub is not created.
Finished testing SAXTransformerFactory...
Start testing Transformer...
ReaderStub is not created.
Finished testing Transformer...
---------------------------------------------------------------------------
======================================================================
The sample test.java (See below) shows that neither SAXTransformerFactory nor
Transformer use the org.xml.sax.helpers.XMLReaderFactory.createXMLReader() method to
create XMLReader for javax.xml.transform.sax.SAXSource object which is not initialized
with reader. But the spec reads :
"public SAXSource(InputSource inputSource)
...
The Transformer or SAXTransformerFactory creates a reader via XMLReaderFactory (if
setXMLReader is not used), sets itself as the reader's ContentHandler, and calls
reader.parse(inputSource)."
Analyzing test failure we found that the implemetations of SAXTransformerFactory and
Transformer don't conform to the javadoc specification. They try first to create the
reader via the javax.xml.parsers.SAXParser and only after failure of that attempt the
XMLReaderFactory is used.
This bug is found in the builds jdk1.4.0-beta3-b83, jaxp-1.1.3 and affects a new JCK1.4
test
api/javax_xml/transform/sax/SAXSource/index.html#Ctor[Ctor003]
------------------------------------test.java-----------------------------
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParserFactory;
import javax.xml.transform.sax.SAXSource;
import javax.xml.transform.sax.SAXTransformerFactory;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.stream.StreamResult;
import org.xml.sax.InputSource;
import org.xml.sax.helpers.XMLFilterImpl;
import org.xml.sax.SAXException;
import java.io.StringReader;
import java.io.StringWriter;
public class test {
public static class ReaderStub extends XMLFilterImpl {
static boolean created = false;
public ReaderStub() throws ParserConfigurationException, SAXException {
super();
super.setParent(SAXParserFactory.newInstance().newSAXParser().getXMLReader());
created = true;
}
}
public static void main (String[] args) {
/* Set own XMLReader instead of default */
System.setProperty("org.xml.sax.driver", ReaderStub.class.getName());
System.out.println("Start testing SAXTransformerFactory...");
testSAXTransformerFactory();
System.out.println("Finished testing SAXTransformerFactory...\n ");
System.out.println("Start testing Transformer...");
testTransformer();
System.out.println("Finished testing Transformer...\n ");
}
private static void testTransformer() {
String xml = "<?xml version='1.0'?><root/>";
ReaderStub.created = false;
try {
TransformerFactory transFactory = TransformerFactory.newInstance();
Transformer transformer = transFactory.newTransformer();
InputSource in = new InputSource(new StringReader(xml));
SAXSource source = new SAXSource(in);
StreamResult result = new StreamResult(new StringWriter());
transformer.transform(source, result);
printWasReaderStubCreated();
} catch (TransformerException e) {
System.out.println(e);
}
}
private static void testSAXTransformerFactory() {
String xsl = "<?xml version='1.0'?>\n"
+ "<xsl:stylesheet"
+ " xmlns:xsl='http://www.w3.org/1999/XSL/Transform'"
+ " version='1.0'>\n"
+ " <xsl:template match='/'>Hello World!</xsl:template>\n"
+ "</xsl:stylesheet>\n";
ReaderStub.created = false;
try {
TransformerFactory transFactory = TransformerFactory.newInstance();
if (transFactory.getFeature(SAXTransformerFactory.FEATURE) == false) {
System.out.println("SAXTransformerFactory not supported");
return;
}
InputSource in = new InputSource(new StringReader(xsl));
SAXSource source = new SAXSource(in);
transFactory.newTransformer(source);
printWasReaderStubCreated();
} catch (TransformerException e) {
System.out.println(e);
}
}
private static void printWasReaderStubCreated() {
if (ReaderStub.created) {
System.out.println("\tReaderStub is created.");
} else {
System.out.println("\tReaderStub is not created.");
}
}
}
---------------------------------------------------------------------------
--------------------- test output -----------------------------------------
% java -showversion test
java version "1.4.0-beta3"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta3-b83)
Java HotSpot(TM) Client VM (build 1.4.0-beta3-b83, mixed mode)
Start testing SAXTransformerFactory...
ReaderStub is not created.
Finished testing SAXTransformerFactory...
Start testing Transformer...
ReaderStub is not created.
Finished testing Transformer...
---------------------------------------------------------------------------
======================================================================