The reason for finding this was a bug in my XQuery coding. While searching
for it, I came across a NullPointerException. I tried to reduce it to a minimum
query, and the smallest reproduction I could find is:

    let $t := text{<e>0</e>/data((+., @a))} return max($t)
Interestingly, the exception does not show up when the query is fired from
the command line via net.sf.saxon.Query. I do however get it when submitting
it to Kernow, or to this Java code:

    import net.sf.saxon.Configuration;
    import net.sf.saxon.query.DynamicQueryContext;
    import net.sf.saxon.query.StaticQueryContext;
    import net.sf.saxon.query.XQueryExpression;   
    public class XQuery
      public static void main(String[] args) throws Exception
        Configuration c = new Configuration();
        StaticQueryContext s = new StaticQueryContext(c);
        XQueryExpression e = s.compileQuery(args[0]);
        DynamicQueryContext d = new DynamicQueryContext(c);
        StreamResult r = new StreamResult(System.out);, r, null);

This occurs with Saxon and Java 1.5 or 1.6.

Best regards

        at net.sf.saxon.expr.Expression.getExecutable(
        at net.sf.saxon.expr.SingletonAtomizer.getItemType(
        at net.sf.saxon.expr.UntypedAtomicConverter.getItemType(
        at net.sf.saxon.expr.ArithmeticExpression.getItemType(
        at net.sf.saxon.instruct.Block.getItemType(
        at net.sf.saxon.expr.Atomizer.computeSingleValued(
        at net.sf.saxon.expr.Atomizer.<init>(
        at net.sf.saxon.expr.Atomizer.copy(
        at net.sf.saxon.expr.AtomicMappingExpression.copy(
        at net.sf.saxon.instruct.QuerySimpleContentConstructor.copy(
        at net.sf.saxon.instruct.ValueOf.copy(
        at net.sf.saxon.expr.PromotionOffer.accept(
        at net.sf.saxon.expr.VariableReference.promote(
        at net.sf.saxon.expr.Expression.doPromotion(
        at net.sf.saxon.expr.UnaryExpression.promote(
        at net.sf.saxon.expr.Expression.doPromotion(
        at net.sf.saxon.expr.FunctionCall.promote(
        at net.sf.saxon.expr.Expression.doPromotion(
        at net.sf.saxon.expr.LetExpression.replaceVariable(
        at net.sf.saxon.expr.LetExpression.optimize(
        at net.sf.saxon.query.XQueryExpression.<init>(
        at net.sf.saxon.query.QueryParser.makeXQueryExpression(
        at net.sf.saxon.query.StaticQueryContext.compileQuery(

Software AG – Sitz/Registered office: Uhlandstraße 12, 64297 Darmstadt, Germany, – Registergericht/Commercial register: Darmstadt HRB 1562 - Vorstand/ Management Board: Karl-Heinz Streibich (Vorsitzender/Chairman), David Broadbent, Mark Edwards, Holger Friedrich, Dr. Peter Kürpick, Arnd Zinnhardt; - Aufsichtsratsvorsitzender/ Chairman of the Supervisory Board: Frank F. Beelitz -