Project

Profile

Help

Bug #6116

closed

UncheckedXPathException and missing error codes in output with Saxon-HE 12J

Added by A Galtman 10 months ago. Updated 5 months ago.

Status:
Closed
Priority:
Low
Assignee:
Category:
Diagnostics
Sprint/Milestone:
-
Start date:
2023-07-06
Due date:
% Done:

100%

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

Description

These issues are like https://saxonica.plan.io/issues/6081 but are not addressed by Saxon 12.3. (Maybe you were right when you mentioned "other paths where the same thing needs to be done...")

Prerequisites for Reproduction Steps

Download and unzip XSpec from the master branch https://github.com/xspec/xspec/archive/refs/heads/master.zip

Case 1: UncheckedXPathException and no user-defined error code

Place the attached file no-by-default-compiled.xq directly in the xspec-master folder.

In a command shell, navigate to the xspec-master folder and run the query with Saxon-HE 12.3 and Saxon-HE 11.5.

Saxon 11.5 results

java -cp "C:\Program Files\Saxonica\SaxonHE11.5J\saxon-he-11.5.jar" net.sf.saxon.Query -q:no-by-default-compiled.xq

Error on line 45 column 8 of no-by-default-compiled.xq:
  my-error-code  Error signalled by application call on error()
     invoked by function call at file:/C:/.../xspec-master/no-by-default-compiled.xq#90
<?xml version="1.0" encoding="UTF-8"?>
<report xmlns="http://www.jenitennison.com/xslt/xspec"
         xspec="test/catch/no-by-default.xspec"
         query="x-urn:test:do-nothing"
         query-at="test/do-nothing.xqm"
         date="2023-07-05T19:14:03.5260578-04:00">
   <scenario id="scenario1" xspec="test/catch/no-by-default.xspec">
      <label>By default</label>
      <input-wrap xmlns="">
         <x:call xmlns:x="http://www.jenitennison.com/xslt/xspec"
                  xmlns:xs="http://www.w3.org/2001/XMLSchema"
                  function="error">
            <x:param select="xs:QName('my-error-code')"/>
         </x:call>
      </input-wrap>
Query failed with dynamic error: Error signalled by application call on error()

Saxon 12.3 results

java -cp "C:\Program Files\Saxonica\SaxonHE12.3J\saxon-he-12.3.jar" net.sf.saxon.Query -q:no-by-default-compiled.xq

<?xml version="1.0" encoding="UTF-8"?>
net.sf.saxon.trans.UncheckedXPathException: Error signalled by application call on error()
	at net.sf.saxon.value.SingletonClosure.materialize(SingletonClosure.java:164)
	at net.sf.saxon.expr.elab.LocalVariableEvaluator.evaluate(LocalVariableEvaluator.java:31)
	at net.sf.saxon.expr.elab.LearningEvaluator.evaluate(LearningEvaluator.java:61)
	at net.sf.saxon.expr.UserFunctionCall.evaluateArguments(UserFunctionCall.java:616)
	at net.sf.saxon.expr.UserFunctionCall$UserFunctionCallElaborator.lambda$elaborateForPush$5(UserFunctionCall.java:844)
	at net.sf.saxon.expr.instruct.Block$BlockElaborator.lambda$elaborateForPush$1(Block.java:851)
	at net.sf.saxon.expr.LetExpression$LetExprElaborator.lambda$elaborateForPush$6(LetExpression.java:942)
	at net.sf.saxon.expr.instruct.Block$BlockElaborator.lambda$elaborateForPush$4(Block.java:895)
	at net.sf.saxon.expr.instruct.ComputedElement$ComputedElementElaborator.lambda$elaborateForPush$1(ComputedElement.java:655)
	at net.sf.saxon.expr.ItemChecker$ItemCheckerElaborator.lambda$elaborateForPush$2(ItemChecker.java:481)
	at net.sf.saxon.expr.instruct.UserFunction.process(UserFunction.java:730)
	at net.sf.saxon.expr.UserFunctionCall$UserFunctionCallElaborator.lambda$elaborateForPush$5(UserFunctionCall.java:846)
	at net.sf.saxon.expr.instruct.Block$BlockElaborator.lambda$elaborateForPush$4(Block.java:895)
	at net.sf.saxon.expr.instruct.ComputedElement$ComputedElementElaborator.lambda$elaborateForPush$1(ComputedElement.java:655)
	at net.sf.saxon.expr.instruct.DocumentInstr$DocumentInstrElaborator.lambda$elaborateForItem$3(DocumentInstr.java:392)
	at net.sf.saxon.expr.instruct.DocumentInstr$DocumentInstrElaborator.lambda$elaborateForPush$0(DocumentInstr.java:332)
	at net.sf.saxon.query.XQueryExpression.processQuery(XQueryExpression.java:499)
	at net.sf.saxon.query.XQueryExpression.run(XQueryExpression.java:473)
	at net.sf.saxon.s9api.XQueryEvaluator.run(XQueryEvaluator.java:464)
	at net.sf.saxon.Query.runQuery(Query.java:1001)
	at net.sf.saxon.Query.doQuery(Query.java:457)
	at net.sf.saxon.Query.doQuery(Query.java:516)
	at net.sf.saxon.Query.main(Query.java:107)
Caused by: net.sf.saxon.functions.Error$UserDefinedXPathException: Error signalled by application call on error()
	at net.sf.saxon.functions.Error.error(Error.java:67)
	at net.sf.saxon.functions.Error.call(Error.java:121)
	at net.sf.saxon.expr.SystemFunctionCall$SystemFunctionCallElaborator.lambda$elaborateForPull$1(SystemFunctionCall.java:605)
	at net.sf.saxon.value.SingletonClosure.asItem(SingletonClosure.java:111)
	at net.sf.saxon.value.SingletonClosure.materialize(SingletonClosure.java:162)
	... 22 more
Fatal error during query: net.sf.saxon.trans.UncheckedXPathException: Error signalled by application call on error()

Case 2: UncheckedXPathException and no standard error code XPDY0002

Place the attached file test-issue-423-compiled.xq directly in the xspec-master folder.

In a command shell, navigate to the xspec-master folder and run the query with Saxon-HE 12.3 and Saxon-HE 11.5.

Saxon 11.5 results

java -cp "C:\Program Files\Saxonica\SaxonHE11.5J\saxon-he-11.5.jar" net.sf.saxon.Query -q:test-issue-423-compiled.xq

Warning on line 41 column 2 of test-issue-423-compiled.xq:
   Evaluation will always throw a dynamic error: Axis step child::element() cannot be used
  here: the context item is absent
Error on line 41 column 2 of test-issue-423-compiled.xq:
  XPDY0002  Axis step child::element() cannot be used here: the context item is absent
     invoked by function call at file:/C:/.../xspec-master/test-issue-423-compiled.xq#88
<?xml version="1.0" encoding="UTF-8"?>
<report xmlns="http://www.jenitennison.com/xslt/xspec"
         xspec="test/issue-423/test.xspec"
         query="x-urn:test:do-nothing"
         query-at="test/do-nothing.xqm"
         date="2023-07-05T19:04:56.3826905-04:00">
   <scenario id="scenario1" xspec="test/issue-423/test.xspec">
      <label>Suppose you're testing count() function with child::element() selected but you
			forget to provide the selection context (either inner XML or @href)</label>
      <input-wrap xmlns="">
         <x:call xmlns:x="http://www.jenitennison.com/xslt/xspec" function="count">
            <x:param select="child::element()"/>
         </x:call>
      </input-wrap>
Query failed with dynamic error: Axis step child::element() cannot be used here: the context item is absent

Saxon 12.3 results

java -cp "C:\Program Files\Saxonica\SaxonHE12.3J\saxon-he-12.3.jar" net.sf.saxon.Query -q:test-issue-423-compiled.xq

Warning on line 41 column 2 of test-issue-423-compiled.xq:
  SXWN9027  Evaluation will always throw a dynamic error: Axis step child::element() cannot
  be used here: the context item is absent
<?xml version="1.0" encoding="UTF-8"?>
net.sf.saxon.trans.UncheckedXPathException: Axis step child::element() cannot be used here: the context item is absent
	at net.sf.saxon.value.SingletonClosure.materialize(SingletonClosure.java:164)
	at net.sf.saxon.expr.elab.LocalVariableEvaluator.evaluate(LocalVariableEvaluator.java:31)
	at net.sf.saxon.expr.elab.LearningEvaluator.evaluate(LearningEvaluator.java:61)
	at net.sf.saxon.expr.UserFunctionCall.evaluateArguments(UserFunctionCall.java:616)
	at net.sf.saxon.expr.UserFunctionCall$UserFunctionCallElaborator.lambda$elaborateForPush$5(UserFunctionCall.java:844)
	at net.sf.saxon.expr.instruct.Block$BlockElaborator.lambda$elaborateForPush$1(Block.java:851)
	at net.sf.saxon.expr.LetExpression$LetExprElaborator.lambda$elaborateForPush$6(LetExpression.java:942)
	at net.sf.saxon.expr.instruct.Block$BlockElaborator.lambda$elaborateForPush$4(Block.java:895)
	at net.sf.saxon.expr.instruct.ComputedElement$ComputedElementElaborator.lambda$elaborateForPush$1(ComputedElement.java:655)
	at net.sf.saxon.expr.ItemChecker$ItemCheckerElaborator.lambda$elaborateForPush$2(ItemChecker.java:481)
	at net.sf.saxon.expr.instruct.UserFunction.process(UserFunction.java:730)
	at net.sf.saxon.expr.UserFunctionCall$UserFunctionCallElaborator.lambda$elaborateForPush$5(UserFunctionCall.java:846)
	at net.sf.saxon.expr.instruct.Block$BlockElaborator.lambda$elaborateForPush$4(Block.java:895)
	at net.sf.saxon.expr.instruct.ComputedElement$ComputedElementElaborator.lambda$elaborateForPush$1(ComputedElement.java:655)
	at net.sf.saxon.expr.instruct.DocumentInstr$DocumentInstrElaborator.lambda$elaborateForItem$3(DocumentInstr.java:392)
	at net.sf.saxon.expr.instruct.DocumentInstr$DocumentInstrElaborator.lambda$elaborateForPush$0(DocumentInstr.java:332)
	at net.sf.saxon.query.XQueryExpression.processQuery(XQueryExpression.java:499)
	at net.sf.saxon.query.XQueryExpression.run(XQueryExpression.java:473)
	at net.sf.saxon.s9api.XQueryEvaluator.run(XQueryEvaluator.java:464)
	at net.sf.saxon.Query.runQuery(Query.java:1001)
	at net.sf.saxon.Query.doQuery(Query.java:457)
	at net.sf.saxon.Query.doQuery(Query.java:516)
	at net.sf.saxon.Query.main(Query.java:107)
Caused by: net.sf.saxon.trans.XPathException: Axis step child::element() cannot be used here: the context item is absent
	at net.sf.saxon.expr.ErrorExpression$ErrorExpressionElaborator.lambda$elaborateForPull$0(ErrorExpression.java:252)
	at net.sf.saxon.functions.Count$CountFnElaborator.lambda$elaborateForItem$0(Count.java:130)
	at net.sf.saxon.expr.elab.ItemElaborator.lambda$elaborateForPull$0(ItemElaborator.java:36)
	at net.sf.saxon.value.SingletonClosure.asItem(SingletonClosure.java:111)
	at net.sf.saxon.value.SingletonClosure.materialize(SingletonClosure.java:162)
	... 22 more
Fatal error during query: net.sf.saxon.trans.UncheckedXPathException: Axis step child::element() cannot be used here: the context item is absent

Files

no-by-default-compiled.xq (3.65 KB) no-by-default-compiled.xq Query for Case 1 A Galtman, 2023-07-06 01:24
test-issue-423-compiled.xq (3.57 KB) test-issue-423-compiled.xq Query for Case 2 A Galtman, 2023-07-06 01:24
Actions #1

Updated by Michael Kay 10 months ago

Case 1 fixed by catching UncheckedXPathException in LocalVariableEvaluator.evaluate().

Actions #2

Updated by Michael Kay 10 months ago

The same patch fixes case 2.

Actions #3

Updated by Michael Kay 10 months ago

  • Category set to Diagnostics
  • Status changed from New to Resolved
  • Assignee set to Michael Kay
  • Applies to branch 12, trunk added
  • Fix Committed on Branch 12, trunk added
  • Platforms .NET, Java added

I have changed Sequence.materialize() to throw a checked XPathException if lazy evaluation fails. I found there were many paths calling materialize() that were failing to check for this failure.

Actions #4

Updated by O'Neil Delpratt 5 months ago

  • Status changed from Resolved to Closed
  • % Done changed from 0 to 100
  • Fixed in Maintenance Release 12.4 added

Bug fix applied in the Saxon 12.4 maintenance release

Please register to edit this issue

Also available in: Atom PDF