GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [core] Jaxen adapter implements document nodes incorrectly · Issue #1938 · pmd/pmd

[core] Jaxen adapter implements document nodes incorrectly #1938

New issue
Copy link
New issue
Copy link
Closed as not planned
#2872
Closed as not planned
[core] Jaxen adapter implements document nodes incorrectly#1938
#2872
Copy link
Labels
in:xpathRelating to xpath support at large, eg Jaxen / Saxon, custom functions, attribute resolutionwas:wontfix

Description

@oowekyala
oowekyala
opened on Jul 23, 2019
Issue body actions

The XPath spec expects that the data model (our adapter implementation) respect the XPath data model spec. Among other things, this mandates a separation between regular element nodes, and the document node:

  • Element nodes are regular XML elements eg <foo>text</foo>. In our model those correspond to AST nodes.
  • The document node is virtual. It is not an element. It is always the root of the DOM. Perhaps surprisingly, it may have several children. The key restriction, is that only a single child may be an element node. This means there can be children comments, or processing instructions. (Processing instructions are not well known but basically are those <? ?> delimited nodes, eg FXML imports)

The point is, that equating the node that is at the top of a tree and the document node doesn't respect this specification. Our Jaxen adapter does this at the moment, and for that reason, there is yet another inconsistency between our XPath implementations. The document node contains a root element node - this is why the XPath kind test form document-node(element(CompilationUnit)) exists.

Explanation of the linked example To understand what's happening in the linked example, consider the following:
  • As per XPath specification:
    • the expression / (a single slash) is perfectly valid and yields the special document node (!= root element).
    • Starting a path expression with a slash evaluates the expression against the document node.
    • A segment in a path expression with just a name (eg UserClass) implicitly uses the child axis (so is equivalent to child::UserClass)
  • So what's the difference between Jaxen and Saxon here?
  • With our Jaxen adapter, the document node is the root element node. So /UserClass expands to /child::UserClass. The problem is that our implementation considers that /, the document node, is the root UserClass. So /child::UserClass actually only yields UserClass that are children of the root of the AST -> meaning, not the root UserClass, but only nested classes. So to actually get the root element you have to use /self::UserClass
  • Out Saxon adapter does the right thing and the document node is properly separated from the root UserClass, so that / evaluates to a DocumentNode instance whose only child is the root UserClass. So /UserClass actually yields the top-level class.

This is yet another nail in the coffin of our Jaxen adapter.

Anyway we should be paying attention to that when refactoring XPath support, and in particular:

  • Check that the expression / evaluates to the synthetic document node
  • Check the expression (/)[self::document-node()] yields a non-empty sequence
  • Check that eg for Java, the expression (/)[self::document-node(element(CompilationUnit))] yields a non-empty sequence

Activity

  1. oowekyala
    added
    in:xpathRelating to xpath support at large, eg Jaxen / Saxon, custom functions, attribute resolution
    on Jul 23, 2019
  2. oowekyala
    added this to the 7.0.0 milestone on Jul 23, 2019
  3. oowekyala
    added a commit that references this issue on Mar 28, 2020

    Fix ClassWithOnlyPrivateConstructorsShouldBeFinal

    b7af5fb
  4. oowekyala
    added 3 commits that reference this issue on Oct 26, 2020

    Check result of / expression

    7a8ca28

    Test remaining cases of pmd#1938

    0a4dd81

    Document pmd#1938 in migration guide

    27441ae
  5. oowekyala
    added
    was:wontfix
    on Oct 26, 2020
  6. oowekyala
    linked a pull request that will close this issue[core] Test some XPath corner cases #2872on Oct 27, 2020
  7. oowekyala
    closed this as completedin #2872on Oct 28, 2020
  8. adangel
    removed this from the 7.0.0 milestone on Oct 30, 2020
  9. rmohan20
    added a commit that references this issue on Dec 15, 2020

    Pulling latest changes from pmd/pmd: 12/15/2020 (#1)

    62c9b8f
  10. adangel commented on Jan 11, 2023

    @adangel
    adangel
    on Jan 11, 2023
    Member
    More actions

    Moved comment from #2523 to here:

    ❌ Won't fix for PMD6, Saxon has correct behavior

    We probably don't need to fix this, since Jaxen will be removed. Won't fix for PMD 6.

    But it's worth to document in that in the XPath rule guide: what is the document node, what the root node and how to search (in other words: what's the difference between /RootNode, //RootNode, /child::RootNode, /self::RootNode, ...).

    / -> virtual document node, (/)[self::document-node()] is a sequence with the document-node in it, (/)[self::document-node(element(CompilationUnit))] is a sequence with the document-node in it, if the document has "CompilationUnit" as a root node.

    I don't think we should document this, apart from the migration guide. This is a tiny corner case.

    I'd suggest to rephrase this task.

  11. adangel
    closed this as not plannedon Jan 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    in:xpathRelating to xpath support at large, eg Jaxen / Saxon, custom functions, attribute resolutionwas:wontfix

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.