#480 NullPointerException with optimized filter expression

v8.7
closed
5
2014-08-19
2006-03-04
Michael Kay
No

The following query:

declare function local:foo(){
((<e1 id="1" att1="1"/>, <e1 id="5" att1="2"/>, <e1 id="3" att1="3"/>, <e1 id="4" att1="4"/>)[fn:position()
< 3]
)[./@id = 5]
};
local:foo()

generates the spurious error message

java.lang.NullPointerException: Unbound function call
local:foo

There are a number of problems interacting here.
Firstly, it's a bad error message. The cause of the
NullPointerException has nothing to do with the
function call being unbound.

The NullPointerException occurs because a rewrite of
the function body has left a subexpression with no
pointer to its parent expression. (a) this shouldn't
occur, and (b) if it does occur, Saxon should recover
from the situation.

The initial cause in this case is that a rewrite of a
filter expression with a positional range [position() >
3]
isn't fixing up the tree correctly. This is solved
by the attached replacement module for
net.sf.saxon.expr.FilterExpression.

The NullPointerException is caused by the code at line
711 of net.sf.saxon.expr.ComputedExpression. This can
be fixed by changing the method getHostLanguage to read:

public int getHostLanguage() {
    if (parentExpression == null) {
        // this shouldn't happen, but it's been known
        return Configuration.XSLT;
    }
    return parentExpression.getHostLanguage();
}

(I've chosen to default the host language to XSLT here.
Since this is used on exception paths only, and it's
rare for the choice of host language to make a
difference, this is entirely arbitrary).

Discussion

  • Michael Kay

    Michael Kay - 2006-03-04

    Replacement code for net.sf.saxon.expr.FilterExpression

     
  • Kevin Rodgers

    Kevin Rodgers - 2006-03-15

    Logged In: YES
    user_id=662991

    For this fix to compile,
    net/sf/saxon/expr/ComputedExpression.java needs an
    additional import statement:

    import net.sf.saxon.Configuration;

    Thanks,

    Kevin