The axes preceding-sibling and following-sibling should be empty on an attribute nodes. Instead, an array index out of bounds exception is thrown:
let $d := <a b="c"/>
return empty($d/@b/preceding-sibling::*)
### What did you expect
`true` should be returned (see https://www.w3.org/TR/xpath/#axes). Instead, the following exception is thrown:
java.lang.ArrayIndexOutOfBoundsException: -1
at org.exist.dom.memtree.DocumentImpl.getFirstChildFor(DocumentImpl.java:630) ~[exist.jar:?]
at org.exist.dom.memtree.NodeImpl.selectPrecedingSiblings(NodeImpl.java:787) ~[exist.jar:?]
at org.exist.xquery.value.ValueSequence.getPrecedingSiblings(ValueSequence.java:630) ~[exist.jar:?]
at org.exist.xquery.LocationStep.getSiblings(LocationStep.java:875) ~[exist.jar:?]
at org.exist.xquery.LocationStep.eval(LocationStep.java:450) ~[exist.jar:?]
at org.exist.xquery.PathExpr.eval(PathExpr.java:269) ~[exist.jar:?]
at org.exist.xquery.DebuggableExpression.eval(DebuggableExpression.java:58) ~[exist.jar:?]
at org.exist.xquery.LetExpr.eval(LetExpr.java:111) ~[exist.jar:?]
at org.exist.xquery.AbstractExpression.eval(AbstractExpression.java:71) ~[exist.jar:?]
at org.exist.xquery.PathExpr.eval(PathExpr.java:276) ~[exist.jar:?]
at org.exist.xquery.AbstractExpression.eval(AbstractExpression.java:71) ~[exist.jar:?]
at org.exist.xquery.XQuery.execute(XQuery.java:253) ~[exist.jar:?]
at org.exist.xquery.XQuery.execute(XQuery.java:185) ~[exist.jar:?]
at org.exist.http.servlets.XQueryServlet.process(XQueryServlet.java:470) [exist-optional.jar:?]
at org.exist.http.servlets.XQueryServlet.doPost(XQueryServlet.java:191) [exist-optional.jar:?]
...
Execute the query in eXide
I can confirm this is a bug and I have been able to produce a fix.
I see in getPrecedingSiblings() :
// if the context node is an attribute or namespace node, the preceding-sibling axis is empty
if (node.getNodeType() != Node.ATTRIBUTE_NODE) {
Where is the Namespace node test ?
Same issue for getFollowingSiblings()
@brihaye AFAIK there is no separate Node type for a Namespace Node.
Most helpful comment
I can confirm this is a bug and I have been able to produce a fix.