Project

Profile

Help

Bug #5641

closed

XQuery error leads to Java stack with internal error, sometimes

Added by Mary Holstege over 1 year ago. Updated about 1 year ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Diagnostics
Sprint/Milestone:
-
Start date:
2022-08-09
Due date:
% Done:

100%

Estimated time:
Legacy ID:
Applies to branch:
11, trunk
Fix Committed on Branch:
11, trunk
Fixed in Maintenance Release:
Platforms:
.NET, Java

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

saxon11-noopt.output.txt (1.14 KB) saxon11-noopt.output.txt Output in Saxon 11 with -opt:0 Mary Holstege, 2022-08-09 22:47
saxon11.output.txt (8.04 KB) saxon11.output.txt Output in Saxon 11 Mary Holstege, 2022-08-09 22:47
saxon10.output.txt (834 Bytes) saxon10.output.txt Output in Saxon 10 Mary Holstege, 2022-08-09 22:47
fail.xqy (571 Bytes) fail.xqy Main Mary Holstege, 2022-08-09 22:47
badframework.xqy (1.44 KB) badframework.xqy Imported module Mary Holstege, 2022-08-09 22:47
Actions #1

Updated by Martin Honnen over 1 year ago

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:
Actions #2

Updated by Michael Kay over 1 year ago

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.

Actions #3

Updated by Michael Kay over 1 year ago

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.

Actions #4

Updated by Michael Kay over 1 year ago

  • 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

Diagnostics improved.

Actions #5

Updated by Community Admin over 1 year ago

  • % 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

Actions #6

Updated by O'Neil Delpratt about 1 year ago

  • Fixed in Maintenance Release 11.5 added

Bug applied in the Saxon 11.5 Maintenance release.

Actions #7

Updated by O'Neil Delpratt about 1 year ago

  • Status changed from Resolved to Closed

Please register to edit this issue

Also available in: Atom PDF