Project

Profile

Help

Maintenance: Planio will be observing a scheduled maintenance window this Tuesday, November 5, 2024 from 03:00 UTC until 06:30 UTC to perform urgent network maintenance in our primary data center. Your Planio account will be unavailable during this maintenance window.

Bug #4556

closed

UnsupportedOperationException on Saxon 10.1

Added by Gunther Rademacher over 4 years ago. Updated about 4 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Internals
Sprint/Milestone:
-
Start date:
2020-05-16
Due date:
% Done:

100%

Estimated time:
Legacy ID:
Applies to branch:
10
Fix Committed on Branch:
10
Fixed in Maintenance Release:
Platforms:

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

bug4556.ebnf (725 Bytes) bug4556.ebnf Gunther Rademacher, 2020-05-17 22:03
bug4556.xquery (32.9 KB) bug4556.xquery Gunther Rademacher, 2020-05-17 22:03
Actions #1

Updated by Gunther Rademacher over 4 years ago

This is reproducible with a REx parser for a small grammar (both attached), running from command line:

java net.sf.saxon.Query bug4556.xquery
Actions #2

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.

Actions #3

Updated by Michael Kay over 4 years ago

The bug was introduced by the patch for bug #4508.

Actions #4

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.

Actions #5

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.

Actions #6

Updated by O'Neil Delpratt about 4 years ago

  • Status changed from Resolved to Closed
Actions #7

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

Also available in: Atom PDF