NPE in SystemFunction.computeSpecialProperties

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

NPE in SystemFunction.computeSpecialProperties

Stefan Wachter
Hi all,

when using a stylesheet with the following function:

  <xsl:function name="vdp:doc">
    <xsl:param name="fp" as="xs:string"/>
    <xsl:variable name="f" select="file:new($fp)"/>
    <xsl:if test="file:exists($f)">
      <xsl:sequence select="document(file:toURL($f))"/>
    </xsl:if>
  </xsl:function>

I get the following NPE:

     [java] java.lang.NullPointerException
     [java]     at
net.sf.saxon.functions.SystemFunction.computeSpecialProperties(SystemFunction.java:164)
     [java]     at
net.sf.saxon.expr.ComputedExpression.computeStaticProperties(ComputedExpression.java:285)
     [java]     at
net.sf.saxon.expr.ComputedExpression.getSpecialProperties(ComputedExpression.java:274)
     [java]     at
net.sf.saxon.style.XSLVariableDeclaration.fixupReferences(XSLVariableDeclaration.java:114)
     [java]     at
net.sf.saxon.style.StyleElement.fixupReferences(StyleElement.java:1110)
     [java]     at
net.sf.saxon.style.XSLFunction.fixupReferences(XSLFunction.java:139)
     [java]     at
net.sf.saxon.style.XSLStylesheet.preprocess(XSLStylesheet.java:633)
     [java]     at
net.sf.saxon.PreparedStylesheet.setStylesheetDocument(PreparedStylesheet.java:279)
     [java]     at
net.sf.saxon.PreparedStylesheet.prepare(PreparedStylesheet.java:117)
     [java]     at
net.sf.saxon.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:130)
     [java]     at net.sf.saxon.Transform.doMain(Transform.java:435)
     [java]     at net.sf.saxon.Transform.main(Transform.java:60)
 
Adding a "treat as" clause to the above variable instruction solves the
problem:

    <xsl:variable name="f" select="file:new($fp treat as xs:string)"/>

--Stefan



-------------------------------------------------------
This SF.Net email is sponsored by the JBoss Inc.  Get Certified Today
Register for a JBoss Training Course.  Free Certification Exam
for All Training Attendees Through End of 2005. For more info visit:
http://ads.osdn.com/?ad_id=7628&alloc_id=16845&op=click
_______________________________________________
saxon-help mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help
Reply | Threaded
Open this post in threaded view
|

RE: NPE in SystemFunction.computeSpecialProperties

Michael Kay
Thanks. This looks like a pretty innocuous function but it turns out that
it's going down a rarely used path. The essential problem is that when Saxon
first sees the extension function call file:new() it hasn't done the type
analysis so it doesn't know what $p is, and therefore can't decide which of
the possible constructors of java.io.File is going to be called. So it saves
a partially-resolved function call in the expression tree and comes back to
it later when more type information is available. In the meantime, however,
something is reading the expression tree and trips over the missing
information.

I've fixed the source code: in the meantime your workaround is a good one
(I'm impressed that you found it!)

Michael Kay
http://www.saxonica.com/
 

> -----Original Message-----
> From: [hidden email]
> [mailto:[hidden email]] On Behalf Of
> Stefan Wachter
> Sent: 16 November 2005 17:13
> To: [hidden email]
> Subject: [saxon] NPE in SystemFunction.computeSpecialProperties
>
> Hi all,
>
> when using a stylesheet with the following function:
>
>   <xsl:function name="vdp:doc">
>     <xsl:param name="fp" as="xs:string"/>
>     <xsl:variable name="f" select="file:new($fp)"/>
>     <xsl:if test="file:exists($f)">
>       <xsl:sequence select="document(file:toURL($f))"/>
>     </xsl:if>
>   </xsl:function>
>
> I get the following NPE:
>
>      [java] java.lang.NullPointerException
>      [java]     at
> net.sf.saxon.functions.SystemFunction.computeSpecialProperties
> (SystemFunction.java:164)
>      [java]     at
> net.sf.saxon.expr.ComputedExpression.computeStaticProperties(C
> omputedExpression.java:285)
>      [java]     at
> net.sf.saxon.expr.ComputedExpression.getSpecialProperties(Comp
> utedExpression.java:274)
>      [java]     at
> net.sf.saxon.style.XSLVariableDeclaration.fixupReferences(XSLV
> ariableDeclaration.java:114)
>      [java]     at
> net.sf.saxon.style.StyleElement.fixupReferences(StyleElement.j
> ava:1110)
>      [java]     at
> net.sf.saxon.style.XSLFunction.fixupReferences(XSLFunction.java:139)
>      [java]     at
> net.sf.saxon.style.XSLStylesheet.preprocess(XSLStylesheet.java:633)
>      [java]     at
> net.sf.saxon.PreparedStylesheet.setStylesheetDocument(Prepared
> Stylesheet.java:279)
>      [java]     at
> net.sf.saxon.PreparedStylesheet.prepare(PreparedStylesheet.java:117)
>      [java]     at
> net.sf.saxon.TransformerFactoryImpl.newTemplates(TransformerFa
> ctoryImpl.java:130)
>      [java]     at net.sf.saxon.Transform.doMain(Transform.java:435)
>      [java]     at net.sf.saxon.Transform.main(Transform.java:60)
>  
> Adding a "treat as" clause to the above variable instruction
> solves the
> problem:
>
>     <xsl:variable name="f" select="file:new($fp treat as xs:string)"/>
>
> --Stefan
>
>
>
> -------------------------------------------------------
> This SF.Net email is sponsored by the JBoss Inc.  Get Certified Today
> Register for a JBoss Training Course.  Free Certification Exam
> for All Training Attendees Through End of 2005. For more info visit:
> http://ads.osdn.com/?ad_id=7628&alloc_id=16845&op=click
> _______________________________________________
> saxon-help mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/saxon-help
>




-------------------------------------------------------
This SF.Net email is sponsored by the JBoss Inc.  Get Certified Today
Register for a JBoss Training Course.  Free Certification Exam
for All Training Attendees Through End of 2005. For more info visit:
http://ads.osdn.com/?ad_id=7628&alloc_id=16845&op=click
_______________________________________________
saxon-help mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help