Project

Profile

Help

Is NullPointerException as result of call() on zero arity system function like local-name() that default to a context node if no argument exists the expected result?

Added by Martin Honnen over 1 year ago

I was exploring the API exposed on XdmFunctionItem in both SaxonCS 11.4 and SaxonJ HE 11.4 and wondered what would happen if a function like local-name() that in case of zero arity/zero arguments defaults to the context node would do if Invoked (.NET) or being call()ed (Java).

It makes kind of sense that in Java I get

Exception in thread "main" java.lang.NullPointerException
	at net.sf.saxon.functions.ScalarSystemFunction.call(ScalarSystemFunction.java:61)
	at net.sf.saxon.functions.ContextItemAccessorFunction.evaluate(ContextItemAccessorFunction.java:70)
	at net.sf.saxon.functions.ContextItemAccessorFunction.call(ContextItemAccessorFunction.java:85)
	at net.sf.saxon.s9api.XdmFunctionItem.call(XdmFunctionItem.java:181)
	at org.example.Main.main(Main.java:10)

and in C#

System.NullReferenceException
  HResult=0x80004003
  Nachricht = Object reference not set to an instance of an object.
  Quelle = SaxonCS-b6
  Stapelüberwachung:
   bei Saxon.Hej.functions.ScalarSystemFunction.call(XPathContext context, Sequence[] arguments)

 	SaxonCS-b6.dll!Saxon.Hej.functions.ScalarSystemFunction.call(Saxon.Hej.expr.XPathContext context, Saxon.Hej.om.Sequence[] arguments)	Unbekannt
 	SaxonCS-b6.dll!Saxon.Hej.functions.ContextItemAccessorFunction.evaluate(Saxon.Hej.om.Item item, Saxon.Hej.expr.XPathContext context)	Unbekannt
 	SaxonCS-b6.dll!Saxon.Api.XdmFunctionItem.Invoke(Saxon.Api.XdmValue[] arguments, Saxon.Api.Processor processor)	Unbekannt
>	SaxonCS114SystemFunctionCallTest1.dll!Program.<Main>$(string[] args) Zeile 7	C#

but I am kind of wondering whether I have missed an API to provide a context node (to Invoke or call) (other than of course using the 1 arity version) and handing it over as the first argument.


Replies (2)

RE: Is NullPointerException as result of call() on zero arity system function like local-name() that default to a context node if no argument exists the expected result? - Added by Michael Kay over 1 year ago

The Javadoc for XdmFunctionItem.getSystemFunction() says

Note that some functions (those with particular context dependencies) may be unsuitable for dynamic calling.

We should probably improve on that.

In QT4CG we've been improving the spec text on this (and there is more to be done). Essentially, an XDM function item may contain a bound context (not just local variables in the closure, but a bound context item etc) and this is always bound at the point where the function item is created.

The API XdmFunctionItem.getSystemFunction() doesn't give an opportunity to bind a context (or closure) so it's not going to work if the function requires one. We should ideally detect that at the point where the function item is created, not at the point where it is called. In theory we could extend the API to provide a way of supplying/binding the context item, but I can't see any practical use case where that would be useful.

    (1-2/2)

    Please register to reply