#229 NPE when 2nd arg of arithmetic is ()

v8.0
closed
Michael Kay
5
2012-10-08
2004-07-01
Michael Kay
No

If the second argument of an arithmetic operator (such
as +, -, div) is an empty sequence, and if the types of
the operands are known statically to be numeric (or a
combination of numeric and untyped) then a
NullPointerException is thrown

For example (in XQuery):

declare namespace f='f.ns';
declare function f:t1($v1 as xs:integer, $v2 as
xdt:untypedAtomic*) { $v1 div $v2 };
f:t1(5, ())

test case added: qxmp152

Source fix:

change lines 351-352 of ArithmeticExpression.java from

AtomicValue v2 = ((AtomicValue)
operands[1].evaluateItem(context)).getPrimitiveValue();
if (v2 == null) return null;

to

AtomicValue v2 = ((AtomicValue)
operands[1].evaluateItem(context));
if (v2 == null) return null;
v2 = v2.getPrimitiveValue();

Reported against Saxon 8.0 but probably applies to
earlier releases also.

Discussion