Thanks for reporting this, but I suspect you aren't running the latest release - it seems to have been fixed in Saxon 8.3.
 
Michael Kay
http://www.saxonica.com/


From: saxon-help-admin@lists.sourceforge.net [mailto:saxon-help-admin@lists.sourceforge.net] On Behalf Of Marcus.Edwards@digitalsteps.com
Sent: 20 March 2005 08:20
To: saxon-help@lists.sourceforge.net
Subject: [saxon] Bug: NPE in GlobalVariableDefinition.explain()

All,

Passing the '-e' (explain) flag into net.sf.saxon.Query with the following XQuery results in a NPE:
---8<---
declare variable $aVariable as xs:date external;
<result>
{$aVariable}
</result>
---8<---

Exception stacktrace is
---8<---
declare variable aVariable := java.lang.NullPointerException
    at net.sf.saxon.query.GlobalVariableDefinition.explain(GlobalVariableDefinition.java:188)
    at net.sf.saxon.query.StaticQueryContext.explainGlobalVariables(StaticQueryContext.java:602)
    at net.sf.saxon.Query.doMain(Query.java:364)
    at net.sf.saxon.Query.main(Query.java:76)
Fatal error during transformation: null
---8<---

I figure that this is because the explain is happening during static compilation and the external variable values have not been bound yet. Perhaps the following change to net.sf.saxon.query.GlobalVariableDefinition would be better?
---8<---
    /**
     * Produce diagnostic output showing the compiled and optimized expression tree for a function
     * @param pool the namepool to be used
     */
    public void explain(NamePool pool) {
        System.err.print("declare variable " + pool.getDisplayName(nameCode) + " := ");
        if(isParameter) System.err.print("<external>");
        else value.display(4, pool, System.err);
        System.err.println(";");
    }
---8<---

HTH,
Marcus Edwards
Digital Steps Limited
1 Bell Court, Leapale Lane, Guildford, Surrey GU1 4LY
Switchboard: +44 (0)14 8346 9480
Direct: +44 (0)14 8346 9483
Mobile: +44 (0)78 1587 4017
---------------------------------------------------------------------
Disclaimer
This e-mail and any attachments may be confidential and/or legally privileged.
If you have received this email and you are not a named addressee, please
inform the sender at Digital Steps Ltd by phone on +44 (0)1483 469 480 or by
reply email and then delete the email from your system. If you are not a named
addressee you must not use, disclose, distribute, copy, print or rely on this
email. Although Digital Steps Ltd routinely screens for viruses, addressees
should check this email and any attachments for viruses. Digital Steps Ltd
makes no representation or warranty as to the absence of viruses in this email
or any attachments.
------------------------------------------------------- SF email is sponsored by - The IT Product Guide Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now. http://ads.osdn.com/?ad_ide95&alloc_id396&op=ick _______________________________________________ saxon-help mailing list saxon-help@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/saxon-help