GeezerVison is showing github.com — [core] XPath expressions return handling · Issue #1939 · pmd/pmd
[core] XPath expressions return handling #1939
Labels
a:bugPMD crashes or fails to analyse a file.in:xpathRelating to xpath support at large, eg Jaxen / Saxon, custom functions, attribute resolution Description
XPathRule doesn't check the type of the nodes returned by an XPath expression:
|
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
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, 2019added 2 commits that reference this issue
on Oct 26, 2020This issue will close once commit c217848 is merged into the 'main' branch.c217848 This issue will close once commit ddcf353 is merged into the 'main' branch.ddcf353 added a commit that references this issue
on Dec 15, 2020This issue will close once commit 62c9b8f is merged into the 'master' branch.62c9b8f
Metadata
Metadata
a:bugPMD crashes or fails to analyse a file.in:xpathRelating to xpath support at large, eg Jaxen / Saxon, custom functions, attribute resolution Development
No branches or pull requestsIssue actions