You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xalan.apache.org by Richard Jones <ri...@hp.com> on 2008/06/24 17:54:08 UTC
newTransformer returns null
Hi Folks,
I'm having a problem with the following code:
TransformerFactory tFactory = TransformerFactory.newInstance();
Reader reader = new
FileReader("/home/richard/workspace/dspace-trunk/foresite/src/main/resources/rdfxml2rdfa.xsl");
StreamSource xslt = new StreamSource(reader);
Transformer transformer = tFactory.newTransformer(xslt);
and am finding that "transformer" is null. This is confusing, as the
javadocs are explicit on the subject:
newTransformer
public abstract Transformer <http://xml.apache.org/xalan-j/apidocs/javax/xml/transform/Transformer.html> *newTransformer*(Source <http://xml.apache.org/xalan-j/apidocs/javax/xml/transform/Source.html> source)
throws TransformerConfigurationException <http://xml.apache.org/xalan-j/apidocs/javax/xml/transform/TransformerConfigurationException.html>
*Returns:*
A |Transformer| object that may be used to perform a
transformation in a single |Thread|, never |null|.
Am I missing something, or is this a bug? What problems with my code
might be able to generate this null? The specified file does exist, and
as far as I can tell everything up to the last line is working fine.
I'm at a bit of a loss to know where to go next with this, so any help
gratefully appreciated,
Cheers,
Richard
Re: newTransformer returns null
Posted by Henry Zongaro <zo...@ca.ibm.com>.
Hi, Richard.
Richard Jones <ri...@hp.com> wrote on 2008-06-24 11:54:08 AM:
> Transformer transformer = tFactory.newTransformer(xslt);
>
> and am finding that "transformer" is null. This is confusing, as the
> javadocs are explicit on the subject:
>
>
> newTransformer
>
> public abstract Transformer <http://xml.apache.org/xalan-
> j/apidocs/javax/xml/transform/Transformer.html> *newTransformer*(Source
<
> http://xml.apache.org/xalan-j/apidocs/javax/xml/transform/Source.html>
source)
> throws
TransformerConfigurationException <
> http://xml.apache.org/xalan-
> j/apidocs/javax/xml/transform/TransformerConfigurationException.html>
>
> *Returns:*
> A |Transformer| object that may be used to perform a
> transformation in a single |Thread|, never |null|.
This is a bug. See XALANJ-2376.[1] The source of the problem was that
earlier versions of JAXP stated that the default ErrorListener must simply
report any error in System.err output stream, but never throw exceptions,
even in the case of a fatalError. But how could a processor possibly
return something useful from newTransformer if it had suffered a fatal
error?
The Xalan-J developers saw only two choices - throw the exception, despite
the fact that the ErrorListener is supposed to dictate whether an
exception is thrown, or return null, so that the user would at least be
alerted to the problem by the subsequent NullPointerException. The JAXP
Expert Group considered the problem, and decided that the processor should
be permitted to throw the exception in the event of a fatal error, even if
the installed ErrorListener chose not to throw it. So we made the wrong
guess on the outcome, and we haven't yet fixed it.
The work-around is to install an ErroListener that always throws the
reported exception from its fatalError method.
I hope that helps.
Thanks,
Henry
[1] https://issues.apache.org/jira/browse/XALANJ-2376
------------------------------------------------------------------
Henry Zongaro
XML Transformation & Query Development
IBM Toronto Lab T/L 313-6044; Phone +1 905 413-6044
mailto:zongaro@ca.ibm.com