Skip to content

self:: axis inside predicate throws XPST0005 #2445

Open
@rvdb

Description

@rvdb

What is the problem

When used inside a predicate, the self:: axis throws error XPST0005 in some cirumstances, even though nothing is wrong with the expression. This happens with the most recent eXist releases 4.5.0 and 5.0.0-RC5 (and earlier releases).

What did you expect

I would expect the query to run without errors (confirmed with Saxon).

Describe how to reproduce or add a test

Behaviour is the same for in-memory and stored nodes, so these stand-alone test cases will illustrate the problem.

[1]

let $node := 
  <test>
    <el>test <el1>test</el1> test <el2>test</el2></el>
  </test>
return 
    $node/el[self::el1]

This should return an empty result set. Instead following error is being thrown:

org.xmldb.api.base.XMLDBException: exerr:ERROR err:XPST0005 Self::{}el1 called on set of nodes which do not contain any nodes of this name. [at line 5, column 23, source: let $node := 
  <test>
    <el>test <el1>test</el1> test <el2>test</el2></el>
  </test>
return $node/el[self::el1]] [at line 5, column 23]
  at org.exist.xmldb.RemoteXPathQueryService.compile(RemoteXPathQueryService.java:130)
  at org.exist.client.QueryDialog$QueryThread.run(QueryDialog.java:558)
Caused by: org.exist.xquery.XPathException: exerr:ERROR err:XPST0005 Self::{}el1 called on set of nodes which do not contain any nodes of this name. [at line 5, column 23, source: let $node := 
  <test>
    <el>test <el1>test</el1> test <el2>test</el2></el>
  </test>
return $node/el[self::el1]] [at line 5, column 23]
  at org.exist.xmldb.RemoteXPathQueryService.throwXPathException(RemoteXPathQueryService.java:179)
  at org.exist.xmldb.RemoteXPathQueryService.compileAndCheck(RemoteXPathQueryService.java:155)
  at org.exist.xmldb.RemoteXPathQueryService.compile(RemoteXPathQueryService.java:128)
  ... 1 more
Caused by: org.exist.xquery.XPathException: exerr:ERROR err:XPST0005 Self::{}el1 called on set of nodes which do not contain any nodes of this name. [at line 5, column 23, source: let $node := 
  <test>
    <el>test <el1>test</el1> test <el2>test</el2></el>
  </test>
return $node/el[self::el1]] [at line 5, column 23]
  at org.exist.xmldb.RemoteXPathQueryService.throwXPathException(RemoteXPathQueryService.java:179)
  at org.exist.xmldb.RemoteXPathQueryService.compileAndCheck(RemoteXPathQueryService.java:155)
  at org.exist.xmldb.RemoteXPathQueryService.compile(RemoteXPathQueryService.java:128)
  at org.exist.client.QueryDialog$QueryThread.run(QueryDialog.java:558)

Of course, this example is contrived, in order to present a simple test case. It seems, however, that the empty node set returned by the test condition in the predicate is significant. If the self:: axis does select a node (e.g. $node/el[self::el]), the query does run without error.

[2]

I've found another failing variant XQuery where the self:: axis occurs inside a predicate and doesn't select a node. Here, parentheses seem to be triggering the same error:

let $node := 
  <test>
    <el>test <el1>test</el1> test <el2>test</el2></el>
  </test>
return $node/el[descendant::*/(self::el1)]

This should return the node:

<el>test <el1>test</el1> test <el2>test</el2></el>

Instead, above error XPST0005 is being thrown.

Here, the parentheses seem to be crucial. Compare with the same predicate without parentheses:

let $node := 
  <test>
    <el>test <el1>test</el1> test <el2>test</el2></el>
  </test>
return $node/el[descendant::*/self::el1]

...which does return the correct result:

<el>test <el1>test</el1> test <el2>test</el2></el>

I've found a reference to this error message in the ML archives (https://sourceforge.net/p/exist/mailman/message/32496312/), and a bug fix in Github. So there's a chance this issue is related to #249.

Context information

Please always add the following information

  • eXist-db version + Git Revision hash:
  • Java version: oracle 1.8.0_191
  • Operating system: Windows 10
  • 32 or 64 bit: 64 bit
  • How is eXist-db installed? JAR installer
  • Any custom changes in e.g. conf.xml: none

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugissue confirmed as bugxqueryissue is related to xquery implementation

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions