Bug #4556
closedUnsupportedOperationException on Saxon 10.1
100%
Description
After upgrading from 10.0 to 10.1, I am facing a
java.lang.RuntimeException: Internal error evaluating function ...
where the root cause is an UnsupportedOperationException with this stacktrace:
java.lang.UnsupportedOperationException
at net.sf.saxon.value.UntypedAtomicValue.copyAsSubType(UntypedAtomicValue.java:46)
at net.sf.saxon.type.Converter$UpCastingConverter.convert(Converter.java:188)
at net.sf.saxon.type.Converter$UpCastingConverter.convert(Converter.java:180)
at net.sf.saxon.expr.CastExpression.doCast(CastExpression.java:376)
at net.sf.saxon.expr.CastExpression.evaluateItem(CastExpression.java:395)
at net.sf.saxon.expr.CastExpression.evaluateItem(CastExpression.java:30)
at net.sf.saxon.expr.ValueComparison.effectiveBooleanValue(ValueComparison.java:347)
at net.sf.saxon.expr.FilterIterator$NonNumeric.matches(FilterIterator.java:177)
at net.sf.saxon.expr.FilterIterator.getNextMatchingItem(FilterIterator.java:76)
at net.sf.saxon.expr.FilterIterator.next(FilterIterator.java:62)
at net.sf.saxon.tree.iter.UntypedAtomizingIterator.next(UntypedAtomizingIterator.java:44)
at net.sf.saxon.tree.iter.UntypedAtomizingIterator.next(UntypedAtomizingIterator.java:27)
at net.sf.saxon.om.MemoSequence$ProgressiveIterator.next(MemoSequence.java:225)
at net.sf.saxon.expr.parser.ExpressionTool.effectiveBooleanValue(ExpressionTool.java:760)
at net.sf.saxon.expr.Expression.effectiveBooleanValue(Expression.java:890)
at net.sf.saxon.expr.instruct.Choose.choose(Choose.java:946)
at net.sf.saxon.expr.instruct.Choose.iterate(Choose.java:996)
at net.sf.saxon.expr.instruct.BlockIterator.next(BlockIterator.java:49)
at net.sf.saxon.expr.CardinalityCheckingIterator.<init>(CardinalityCheckingIterator.java:51)
at net.sf.saxon.expr.CardinalityChecker.iterate(CardinalityChecker.java:234)
at net.sf.saxon.expr.LetExpression.iterate(LetExpression.java:519)
at net.sf.saxon.value.MemoClosure.makeSequence(MemoClosure.java:86)
at net.sf.saxon.value.MemoClosure.iterate(MemoClosure.java:80)
at net.sf.saxon.expr.UserFunctionCall.iterate(UserFunctionCall.java:482)
at net.sf.saxon.value.MemoClosure.makeSequence(MemoClosure.java:86)
at net.sf.saxon.value.MemoClosure.iterate(MemoClosure.java:80)
at net.sf.saxon.expr.VariableReference.iterate(VariableReference.java:555)
at net.sf.saxon.expr.FirstItemExpression.evaluateItem(FirstItemExpression.java:112)
at net.sf.saxon.expr.Expression.iterate(Expression.java:872)
at net.sf.saxon.expr.Atomizer.iterate(Atomizer.java:359)
at net.sf.saxon.expr.GeneralComparison.effectiveBooleanValue(GeneralComparison.java:646)
at net.sf.saxon.expr.instruct.Choose.choose(Choose.java:946)
at net.sf.saxon.expr.instruct.Choose.iterate(Choose.java:996)
at net.sf.saxon.expr.LetExpression.iterate(LetExpression.java:519)
at net.sf.saxon.expr.instruct.Choose.iterate(Choose.java:997)
at net.sf.saxon.expr.instruct.Choose.iterate(Choose.java:997)
at net.sf.saxon.value.MemoClosure.makeSequence(MemoClosure.java:86)
at net.sf.saxon.value.MemoClosure.iterate(MemoClosure.java:80)
at net.sf.saxon.expr.VariableReference.iterate(VariableReference.java:555)
at net.sf.saxon.expr.FirstItemExpression.evaluateItem(FirstItemExpression.java:112)
at net.sf.saxon.expr.Expression.iterate(Expression.java:872)
at net.sf.saxon.expr.Atomizer.iterate(Atomizer.java:359)
at net.sf.saxon.expr.GeneralComparison.effectiveBooleanValue(GeneralComparison.java:646)
at net.sf.saxon.expr.AndExpression.effectiveBooleanValue(AndExpression.java:145)
at net.sf.saxon.expr.AndExpression.effectiveBooleanValue(AndExpression.java:145)
at net.sf.saxon.expr.AndExpression.effectiveBooleanValue(AndExpression.java:145)
at net.sf.saxon.expr.AndExpression.effectiveBooleanValue(AndExpression.java:145)
at net.sf.saxon.expr.AndExpression.effectiveBooleanValue(AndExpression.java:145)
at net.sf.saxon.expr.AndExpression.effectiveBooleanValue(AndExpression.java:145)
at net.sf.saxon.expr.instruct.Choose.choose(Choose.java:946)
at net.sf.saxon.expr.instruct.Choose.iterate(Choose.java:996)
at net.sf.saxon.expr.LetExpression.iterate(LetExpression.java:519)
at net.sf.saxon.expr.instruct.Choose.iterate(Choose.java:997)
at net.sf.saxon.expr.TailCallLoop.iterate(TailCallLoop.java:99)
at net.sf.saxon.expr.parser.Evaluator$11.evaluate(Evaluator.java:290)
at net.sf.saxon.expr.instruct.UserFunction.call(UserFunction.java:633)
... 231 more
Unfortunately I do not yet have a small reproduction for this, but I am working on it.
Files
Updated by Gunther Rademacher over 4 years ago
- File bug4556.xquery bug4556.xquery added
- File bug4556.ebnf bug4556.ebnf added
This is reproducible with a REx parser for a small grammar (both attached), running from command line:
java net.sf.saxon.Query bug4556.xquery
Updated by Michael Kay over 4 years ago
It's trying to cast an xs:untypedAtomic
value to xs:anyAtomicType
. Such a cast isn't allowed.
It appears to have been generated during rewriting of the predicate on line 998:
@key = $state[$p:e0] * 1 + $dpi]
The code for general comparisons generates a cast expression from UntypedAtomic (the type of @key) to the static type of the RHS, which in this case is xs:anyAtomicType.
The relevant code in GeneralComparison.optimize()
is unchanged from 9.9, but for reasons I can't easily establish, it's not executed in the 9.9 case.
It seems that the static type analysis for the RHS expression has inferred a type of xs:numeric
, and the cast is generated to the corresponding primitive type, which is xs:anyAtomicType
.
The test NumericType.isNumericType()
is returning false if the type is xs:numeric.
In 9.9 the code was th.isSubType(t1, NumericType.getInstance()
, which would return true for any numeric type or for the union type xs:numeric itself.
I think NumericType.isNumericType()
should return true for the union type, but it's a little bit hard to be sure that's what all callers expect.
Changing it fixes this test case and appears to cause no regression.
Updated by Michael Kay over 4 years ago
The bug was introduced by the patch for bug #4508.
Updated by Michael Kay over 4 years ago
- Category set to Internals
- Status changed from New to Resolved
- Assignee set to Michael Kay
- Priority changed from Low to Normal
- Applies to branch 10 added
- Fix Committed on Branch 10 added
Changing NumericType.isNumericType()
to:
public static boolean isNumericType(ItemType type) {
return type.isPlainType() &&
UType.NUMERIC.subsumes(type.getUType());
}
The second condition on its own would probably be fine, but this is extra safety.
Updated by O'Neil Delpratt about 4 years ago
- % Done changed from 0 to 100
- Fixed in Maintenance Release 10.2 added
Bug fix applied in the Saxon 10.2 maintenance release.
Updated by O'Neil Delpratt about 4 years ago
- Status changed from Resolved to Closed
Updated by Gunther Rademacher about 4 years ago
Thanks for the fix - this works fine on Saxon-HE 10.2.
Please register to edit this issue