Bug #5641
closed
XQuery error leads to Java stack with internal error, sometimes
Applies to branch:
11, trunk
Fix Committed on Branch:
11, trunk
Fixed in Maintenance Release:
Description
This is a little tricky to pin down: I have pruned the test case as much as I can.
It is definitely only on Saxon 11, not 10 (see saxon10.output.txt vs saxon11.output.txt).
It is definitely an optimizer issue, as -opt:0 produces a good stack (see saxon11-noopt.output.txt)
It is very sensitive to the details of the call chain (see comments in badframework.xqy)
What happens is that I have a bug in my XQuery code, but I get an ugly Java stack sans nice information on the (XQuery) stack frames.
Run the main fail.xqy
Files
SaxonCS 11.4 also gives an exception:
Analyzing query from .\fail.xqy
Analysis time: 500,7252 milliseconds
<?xml version="1.0" encoding="UTF-8"?>Saxon.Hej.trans.UncheckedXPathException
---> Saxon.Hej.trans.XPathException: Cannot add a map to an XDM node tree
at Saxon.Hej.expr.Expression.process(Outputter output, XPathContext context)
at Saxon.Hej.expr.SystemFunctionCall.process(Outputter output, XPathContext context)
at Saxon.Hej.expr.instruct.ElementCreator.processLeavingTail(Outputter out, XPathContext context, NodeInfo copiedNode)
at Saxon.Hej.expr.instruct.ElementCreator.processLeavingTail(Outputter output, XPathContext context)
at Saxon.Hej.expr.instruct.Instruction.process(Outputter output, XPathContext context)
at Saxon.Hej.expr.parser.Evaluator.Process.evaluate(Expression expr, XPathContext context)
at Saxon.Hej.expr.TailCallLoop.tailCallDifferentFunction(UserFunction userFunction, XPathContextMajor cm)
at Saxon.Hej.expr.TailCallLoop.iterate(XPathContext context)
at Saxon.Hej.value.MemoClosure.makeSequence()
at Saxon.Hej.value.MemoClosure.iterate()
--- End of inner exception stack trace ---
at Saxon.Hej.value.MemoClosure.iterate()
at Saxon.Hej.om.SequenceTool.process(Sequence value, Outputter output, Location locationId)
at Saxon.Hej.expr.instruct.UserFunction.process(XPathContextMajor context, Sequence[] actualArgs, Outputter output)
at Saxon.Hej.expr.UserFunctionCall.process(Outputter output, XPathContext context)
at Saxon.Hej.query.XQueryExpression.run(DynamicQueryContext env, Result result, Properties outputProperties)
at Saxon.Hej.s9api.XQueryEvaluator.run(Destination destination)
at Saxon.Hej.Query.runQuery(XQueryExecutable exp, XQueryEvaluator evaluator, Source input, Destination destination)
at Saxon.Hej.Query.doQuery(String[] args, String command)
Fatal error during query: UncheckedXPathException:
I've added code to SequenceTool.process() that converts the unchecked exception to a (checked) XPathException, and this improves the diagnostics:
Error on line 45 column 11 of badframework.xqy:
XQTY0105 Cannot add a map to an XDM node tree
Focus: absent
Local variables
$externals = map{"ALGORITHM-PARAMETERS":map{},"CONTENT-FUNCTION":this:content}
invoked by function call at file:/Users/mike/bugs/2022/5641-Holstege/badframework.xqy#53
Focus: absent
Local variables
$externals = map{"ALGORITHM-PARAMETERS":map{},"CONTENT-FUNCTION":this:content}
invoked by unknown caller (class net.sf.saxon.value.MemoClosure)
Focus: absent
Local variables
$externals = map{"ALGORITHM-PARAMETERS":map{},"CONTENT-FUNCTION":this:content}
invoked by function call at file:/Users/mike/bugs/2022/5641-Holstege/fail.xqy#21
Query failed with dynamic error: Cannot add a map to an XDM node tree
I think we could do better than this by including the result of Err.depict(map)
in the error message; in this example this would show the offending map as map{"resolution":"medium"}
. We also know that the element we are writing is called art:canvas
, and I think we could work that in too.
With this change we get the diagnostics
Error on line 45 column 11 of badframework.xqy:
XQTY0105 Cannot add a map (map{"resolution":"medium"}) to an XDM node tree (currently
writing element art:canvas)
Focus: absent
Local variables
$externals = map{"ALGORITHM-PARAMETERS":map{},"CONTENT-FUNCTION":this:content}
invoked by function call at file:/Users/mike/bugs/2022/5641-Holstege/badframework.xqy#53
Focus: absent
Local variables
$externals = map{"ALGORITHM-PARAMETERS":map{},"CONTENT-FUNCTION":this:content}
invoked by unknown caller (class net.sf.saxon.value.MemoClosure)
Focus: absent
Local variables
$externals = map{"ALGORITHM-PARAMETERS":map{},"CONTENT-FUNCTION":this:content}
invoked by function call at file:/Users/mike/bugs/2022/5641-Holstege/fail.xqy#21
Query failed with dynamic error: Cannot add a map(map{"resolution":"medium"}) to an XDM node tree (currently writing element art:canvas)
Hopefully this resolves the issue.
- Category set to Diagnostics
- Status changed from New to Resolved
- Assignee set to Michael Kay
- Applies to branch trunk added
- Fix Committed on Branch 11, trunk added
- Platforms .NET, Java added
- % Done changed from 0 to 100
- Fixed in Maintenance Release 12.0 added
Bug issue fix applied in the Saxon 12.0 Major Release.
Leaving this bug marked as Resolved until fix applied
- Fixed in Maintenance Release 11.5 added
Bug applied in the Saxon 11.5 Maintenance release.
- Status changed from Resolved to Closed
Please register to edit this issue
Also available in: Atom
PDF