Menu

#1209 XPath 2.0 following-sibling incorrectly includes context node

PMD-5.1.2
closed
PMD
3-Major
Bug
5.1.1
2014-12-14
2014-06-13
No

The XPath 2.0 parser/handler incorrectly counts a node as one of its own following-sibling:: (as though it were a combination of following-sibling:: and self::)

public class dummy {
  public String toString() {
    String test = "bad example";
    return test;
  }
}
//BlockStatement/following-sibling::BlockStatement

The above code should return one match, for line 4. With xpath version 1.0 it does. With xpath version 2.0 it returns both lines 3 and 4.

This leads to problems with xpaths that are intended to tell if a BlockStatement with certain properties immediately follows a BlockStatement with certain other properties, e.g.

//BlockStatement[descendant::VariableDeclaratorId]/following-sibling::BlockStatement[1]//ReturnStatement

...should match the return statement only if the action just before it was the creation of a variable, but in xpath 2.0 does not because the following-sibling::BlockStatement matches both and then the [1] restricts it to the initial BlockStatement instead of the first BlockStatement after it.

Discussion

  • Andreas Dangel

    Andreas Dangel - 2014-07-15

    This will be fixed with the next release.

     
  • Andreas Dangel

    Andreas Dangel - 2014-07-15
    • status: open --> closed
    • assigned_to: Andreas Dangel
    • Milestone: New Tickets --> PMD-Next
     

Log in to post a comment.