Skip to content

self:: axis inside predicate throws XPST0005 #2445

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
rvdb opened this issue Jan 29, 2019 · 8 comments · May be fixed by #5673
Open

self:: axis inside predicate throws XPST0005 #2445

rvdb opened this issue Jan 29, 2019 · 8 comments · May be fixed by #5673
Labels
bug issue confirmed as bug xquery issue is related to xquery implementation
Milestone

Comments

@rvdb
Copy link
Contributor

rvdb commented Jan 29, 2019

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
@ghost ghost added the triage issue needs to be investigated label Jan 29, 2019
@duncdrum duncdrum added the investigate issues being looked at label Jun 13, 2019
@ghost ghost removed the triage issue needs to be investigated label Jun 13, 2019
@duncdrum
Copy link
Contributor

@wolfgangmm as the author of #249 could you chime in here. I can reproduce these errors, but i am not sure what the optimal fix is here, should [1] really return an empty sequence?

@line-o
Copy link
Member

line-o commented Dec 5, 2020

Retested with e2bf08c
Putting ./ in front of the SELF-axis XPath-(sub-)expressions mitigates the problem.
Maybe, this can also help in tracking down the root-cause.

let $node := 
  <test>
    <el>test <el1>test</el1> test <el2>test</el2></el>
  </test>

return (
    $node/el[./self::el1],
    $node/el[./descendant::*/self::el1],
    $node/el[descendant::*/self::el1],
    $node/el[descendant::*/(./self::el1)]
)

@line-o
Copy link
Member

line-o commented Dec 5, 2020

Maybe, this can also help in tracking down the root-cause.

It confirms that the optimisation added in #249 is the culprit.

While [self::el1] is considered a simple query [./self::el1] is not and therefore is evaluated correctly.

@line-o
Copy link
Member

line-o commented Dec 5, 2020

@wolfgang @adamretter Maybe it would be enough to return an empty sequence instead of throwing an error in these two cases?

if (parent.getSubExpressionCount() == 1 && !Type.subTypeOf(getTest().getType(), cStep.getTest().getType())) {
throw new XPathException(this,
ErrorCodes.XPST0005, "Got nothing from self::" + getTest() + ", because parent node kind " + Type.getTypeName(cStep.getTest().getType()));
}
if (parent.getSubExpressionCount() == 1 && !(cStep.getTest().isWildcardTest() || getTest().isWildcardTest()) && !cStep.getTest().equals(getTest())) {
throw new XPathException(this,
ErrorCodes.XPST0005, "Self::" + getTest() + " called on set of nodes which do not contain any nodes of this name.");
}

@joewiz joewiz added the xquery issue is related to xquery implementation label Dec 5, 2020
@joewiz joewiz added this to the eXist-5.2.1 milestone Dec 5, 2020
@joewiz joewiz added bug issue confirmed as bug and removed investigate issues being looked at labels Dec 5, 2020
@joewiz
Copy link
Member

joewiz commented Dec 5, 2020

A simplified test:

<foo><bar/></foo>/bar[self::baz]

Returns a static error:

Self::{}baz called on set of nodes which do not contain any nodes of this name.

The same query returns the empty sequence in BaseX and Saxon. Only eXist raises this error.

eXist correctly returns empty sequence for other axes:

<foo><bar/></foo>/bar[
    ancestor::baz | ancestor-or-self::baz | attribute::baz | 
    child::baz | descendant::baz | descendant-or-self::baz | 
    following::baz | following-sibling::baz | parent::baz | 
    preceding::baz | preceding-sibling::baz
]

Introducing | self::baz into the predicate triggers the error.

@line-o
Copy link
Member

line-o commented Dec 5, 2020

I have a fix in the making.

line-o added a commit to line-o/exist that referenced this issue Dec 6, 2020
Fixes eXist-db#2445

By definition the following Xpaths must evaluate to an empty sequence
- `<a/>[self::b]`
- `<a/>/@b/c`
- `<a/>/text()/b`

Instead of throwing an Exception the staticReturnType of the current step
and the contextInfo returnType are set to Type.EMPTY.
@line-o
Copy link
Member

line-o commented Dec 7, 2020

The question whether this is a bug or the expected behaviour is a general decision the existdb community has to answer: Do we provide the StaticTyping feature or not.

Even if we decide to adhere to provide the StaticTyping feature it is:

  1. not fully implemented
  2. needs to be clearly communicated to users

@joewiz
Copy link
Member

joewiz commented Dec 7, 2020

As discussed during the Community Call, eXist doesn't implement the Static Typing optional feature (https://www.w3.org/TR/xquery-31/#id-static-typing-feature). Next actions:

line-o added a commit to line-o/exist that referenced this issue Jul 6, 2021
Fixes eXist-db#2445

By definition the following Xpaths must evaluate to an empty sequence
- `<a/>[self::b]`
- `<a/>/@b/c`
- `<a/>/text()/b`

Instead of throwing an Exception the staticReturnType of the current step
and the contextInfo returnType are set to Type.EMPTY.
@adamretter adamretter modified the milestones: eXist-5.3.1, eXist-5.3.2 Dec 16, 2021
@adamretter adamretter modified the milestones: eXist-5.3.2, eXist-6.0.2 Feb 14, 2022
@adamretter adamretter modified the milestones: eXist-6.0.2, eXist-6.1.1 Jan 15, 2023
@adamretter adamretter modified the milestones: eXist-6.1.1, eXist-7.0.1 Feb 4, 2023
line-o added a commit to line-o/exist that referenced this issue Mar 16, 2025
Fixes eXist-db#2445

By definition the following Xpaths must evaluate to an empty sequence
- `<a/>[self::b]`
- `<a/>/@b/c`
- `<a/>/text()/b`

Instead of throwing an Exception the staticReturnType of the current step
and the contextInfo returnType are set to Type.EMPTY.
@line-o line-o linked a pull request Mar 16, 2025 that will close this issue
2 tasks
line-o added a commit to line-o/exist that referenced this issue Mar 16, 2025
Fixes eXist-db#2445

By definition the following Xpaths must evaluate to an empty sequence
- `<a/>[self::b]`
- `<a/>/@b/c`
- `<a/>/text()/b`

Instead of throwing an Exception the staticReturnType of the current step
and the contextInfo returnType are set to Type.EMPTY.
line-o added a commit to line-o/exist that referenced this issue Mar 16, 2025
Fixes eXist-db#2445

By definition the following Xpaths must evaluate to an empty sequence
- `<a/>[self::b]`
- `<a/>/@b/c`
- `<a/>/text()/b`

Instead of throwing an Exception the staticReturnType of the current step
and the contextInfo returnType are set to Type.EMPTY.
line-o added a commit to line-o/exist that referenced this issue Mar 17, 2025
Fixes eXist-db#2445

By definition the following Xpaths must evaluate to an empty sequence
- `<a/>[self::b]`
- `<a/>/@b/c`
- `<a/>/text()/b`

Instead of throwing an Exception the staticReturnType of the current step
and the contextInfo returnType are set to Type.EMPTY.
line-o pushed a commit to line-o/exist that referenced this issue Mar 17, 2025
refs eXist-db#2445
These tests aim to ensure that certain XPath expressions no longer raise error XPST0005 as exist-db does not implement
the static typing feature and this feature is even dropped entirely with the next version of XQuery.
line-o pushed a commit to line-o/exist that referenced this issue Mar 17, 2025
refs eXist-db#2445
These tests aim to ensure that certain XPath expressions no longer raise error XPST0005 as exist-db does not implement
the static typing feature and this feature is even dropped entirely with the next version of XQuery.
line-o pushed a commit to line-o/exist that referenced this issue Mar 17, 2025
refs eXist-db#2445
These tests aim to ensure that certain XPath expressions no longer raise error XPST0005 as exist-db does not implement
the static typing feature and this feature is even dropped entirely with the next version of XQuery.
line-o pushed a commit to line-o/exist that referenced this issue Mar 17, 2025
refs eXist-db#2445
These tests aim to ensure that certain XPath expressions no longer raise error XPST0005 as exist-db does not implement
the static typing feature and this feature is even dropped entirely with the next version of XQuery.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug issue confirmed as bug xquery issue is related to xquery implementation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants