Henry,
Thanks for your reply.  I've tested out your suggestions by using an ErrorHandler (import org.apache.xml.utils.DefaultErrorHandler).
 
// get a Transformer
SAXTransformerFactory tf = (SAXTransformerFactory)SAXTransformerFactory.newInstance();

// Make sure we trap all errors
DefaultErrorHandler erh = new DefaultErrorHandler();
tf.setErrorListener(erh);
 
as well as
 
TransformerHandler th = tf.newTransformerHandler(template);
Transformer t = th.getTransformer();
DefaultErrorHandler erh2 = new DefaultErrorHandler();
t.setErrorListener(erh2);

 
and
 
 
    protected Templates getTemplates (InputStream in)
    throws SAXException, TransformerConfigurationException
    {
        StreamSource ss = new StreamSource(in);
        TransformerFactory tf = TransformerFactory.newInstance ();
        DefaultErrorHandler erh = new DefaultErrorHandler(false);
        tf.setErrorListener(erh);       
        Templates t = tf.newTemplates(ss);

        return (t);
    }
 
The same NPE is being thrown even with the ErrorHandler set.
 
 
I have traced the caused down to this line in TransformerImpl
public void setParameter(String name, String namespace, Object value)
  {

    VariableStack varstack = getXPathContext().getVarStack();
    QName qname = new QName(namespace, name);
    XObject xobject = XObject.create(value, getXPathContext());
   
    StylesheetRoot sroot = m_stylesheetRoot;
    Vector vars = sroot.getVariablesAndParamsComposed();
    int i = vars.size();
    while (--i >= 0)
    {
      ElemVariable variable = (ElemVariable)vars.elementAt(i);
      if(variable.getXSLToken() == Constants.ELEMNAME_PARAMVARIABLE &&
         variable.getName().equals(qname))
      {
          varstack.setGlobalVariable(i, xobject);
      }
    }
  }

So out of curiosity, i changed the way i create a Transformer. Instead of using Templates, i used StreamSource instead.
 
        // Templates  template = getTemplates(xsltStream);
        // TransformerHandler th = tf.newTransformerHandler(template);
        TransformerHandler th = tf.newTransformerHandler( new StreamSource( xsltStream ) );
 
The NPE goes away and I am back to 2.5.1 behavior which is getting a javax.xml.transform.TransformerConfigurationException instead of NPE.
 
Any further thoughts ? 
 
Thanks.


On 5/1/06, Henry Zongaro <[EMAIL PROTECTED] > wrote:
Hello.

"toadie D" < [EMAIL PROTECTED]> wrote on 2006-04-27 01:57:04 PM:
> Thanks for the quick reply.  Yes I would say it's a bit confusing
> and misleading.
> In fact if you comment out these 2 lines in the sample code, v2.7.0
> still throws an NPE, but it's just thrown
> from somewhere else.
>
>         byte[] value  = "<Foo/>".getBytes();
>         t.setParameter("FooParam", value);

    I took a look at your test case, and I think this is actually due to
a usability problem in JAXP 1.3.  JAXP 1.3 says that if no ErrorListener
is set on a TransformerFactory, the default ErrorListener reports messgaes
to System.err, but does not throw exceptions.  JAXP 1.3 also implies that
the processor should not throw TransformerExceptions on its own - that it
should be up to the ErrorListener to decide whether to throw an exception.

    JAXP 1.4 has resolved this usability problem by changing the
specification to say that those methods that create a new Transformer or
Templates object should throw a TransformerConfigurationException if they
are unable to create a new Transformer or Templates object, even if the
ErrorListener chose not to throw an exception.

    Please open a bug report against Xalan-J for this, and attach your
test case to the bug report.  In the meanwhile, you should be able to work
around the problem by creating an ErrorListener object that you set on
TransformerFactory that throws TransformerExceptions if either its error
or its fatalError method is called.  That should restore the behaviour you
observed with Xalan-J 2.5.1.

Thanks,

Henry
------------------------------------------------------------------
Henry Zongaro      Xalan development
IBM SWS Toronto Lab   T/L 969-6044;  Phone +1 905 413-6044
mailto:[EMAIL PROTECTED]



Reply via email to