Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I ran into the same problem, when some of my tests went wrong, after having added a new dependency to the project. Wondering how could this return <strong>null</strong> when its API says it's impossible, I revised it again:</p> <blockquote> <p><em>"Obtain a new instance of a TransformerFactory. This static method creates a new factory instance This method uses the following ordered lookup procedure to determine the TransformerFactory implementation class to load: Use the javax.xml.transform.TransformerFactory system property. ... [lookup order] ... Once an application has obtained a reference to a TransformerFactory it can use the factory to configure and obtain transformer instances."</em></p> </blockquote> <p>So, I had a look at <strong>TransformerFactory API</strong>, too, and it says:</p> <blockquote> <p><em>"The system property that determines which Factory implementation to create is named "javax.xml.transform.TransformerFactory". This property names a concrete subclass of the TransformerFactory abstract class. If the property is not defined, a platform default is be used."</em></p> </blockquote> <p>As I mentioned, the problem started when I added a new dependency to the project: another project that processes XML documents/signatures. I deleted the dependency, ran the test (that failed with the dependency added) and retrieved the specific class of the TransformerFactory. I added the dependency back and ran the test again: it was a different class now. So, as I supposed, the lookup procedure was instantiating a wrong TransformerFactory implementation, finding it in the added jar.</p> <p>I didn't want to fix it adding another system property, so I changed the code like that:</p> <pre><code>private static final String TRANSFORMER_FACTORY_CLASS = "com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl"; TransformerFactory factory = TransformerFactory.newInstance(TRANSFORMER_FACTORY_CLASS, null); //null for default ClassLoader </code></pre> <p>and everything worked fine.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload