TransformerFactory.newInstance().newTransformer(streamSource) returns null

4.2k views Asked by At

How could that be that TransformerFactory.newInstance().newTransformer(streamSource) returns null. According to javadoc this is not possible: http://download.oracle.com/javase/6/docs/api/javax/xml/transform/TransformerFactory.html#newTransformer(javax.xml.transform.Source)

here's groovy code sample

    def is = new ClassPathResource('xslt/MySpace-Contact.xsl').inputStream
    println is
    def streamSource = new StreamSource(is)
    println streamSource
    def factory = TransformerFactory.newInstance()
    println factory
    def tr = factory.newTransformer(streamSource)
    println tr

Here's the output:

--Output from testTransformation--
java.io.BufferedInputStream@32999f10
javax.xml.transform.stream.StreamSource@399ed64
org.apache.xalan.processor.TransformerFactoryImpl@6eb04214
null

2

There are 2 answers

0
Archer On BEST ANSWER

Answering my own question. If XSLT file is not valid, that will happen (newTransformer(Source) will return null). I think that should be reported to Oracle so they change the javadoc. It's still POSSIBLE that null is returned.

1
Peter Niederwieser On

Your script contains a typo. The last statement prints "tf" rather than "tr". "tf" is an uninitialized script variable, hence its value is null.