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] XPath expressions return handling · Issue #1939 · pmd/pmd

[core] XPath expressions return handling #1939

New issue
Copy link
New issue
Copy link
Closed
#2872
Closed
[core] XPath expressions return handling#1939
#2872
Copy link
Labels
a:bugPMD crashes or fails to analyse a file.in:xpathRelating to xpath support at large, eg Jaxen / Saxon, custom functions, attribute resolution
Milestone
6.30.0

Description

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

XPathRule doesn't check the type of the nodes returned by an XPath expression:

pmd/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/SaxonXPathRuleQuery.java

Lines 86 to 95 in 2d4a30f

final List<ElementNode> nodes = xpathExpression.evaluate(xpathDynamicContext);
/*
Map List of Saxon Nodes -> List of AST Nodes, which were detected to match the XPath expression
(i.e. violation found)
*/
final List<Node> results = new ArrayList<>();
for (final ElementNode elementNode : nodes) {
results.add((Node) elementNode.getUnderlyingNode());
}

The assignment of the result of xpathExpression::evaluate to List<ElementNode> line 86 is unchecked, it's actually a list of the more general Item. So when getting a node line 93, the routine will fail with ClassCastException if the element is not actually an ElementNode.

This is not completely outlandish: eg 1+1 is a valid XPath expression that doesn't yield an ElementNode, and so is / (a single slash), which should yield a document node (see #1938)

We should at least ensure that the type of each element is correct

Activity

  1. oowekyala
    added
    a:bugPMD crashes or fails to analyse a file.
    in:xpathRelating to xpath support at large, eg Jaxen / Saxon, custom functions, attribute resolution
    on Jul 23, 2019
  2. oowekyala
    added this to the 6.30.0 milestone on Oct 26, 2020
  3. oowekyala
    added 2 commits that reference this issue on Oct 26, 2020

    Check XPath expression result for correct type

    This issue will close once commit c217848 is merged into the 'main' branch.
    c217848

    Update release notes, refs pmd#1939

    This issue will close once commit ddcf353 is merged into the 'main' branch.
    ddcf353
  4. oowekyala
    closed this as completedin c217848on Oct 28, 2020
  5. rmohan20
    added a commit that references this issue on Dec 15, 2020

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

    This issue will close once commit 62c9b8f is merged into the 'master' branch.
    62c9b8f
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

    a:bugPMD crashes or fails to analyse a file.in:xpathRelating to xpath support at large, eg Jaxen / Saxon, custom functions, attribute resolution

    Type

    No type

    Projects

    No projects

      Milestone

      • 6.30.0

      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.