-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[core] XPath expressions return handling #1939
Copy link
Copy link
Closed
Labels
a:bugPMD crashes or fails to analyse a file.PMD crashes or fails to analyse a file.in:xpathRelating to xpath support at large, eg Jaxen / Saxon, custom functions, attribute resolutionRelating to xpath support at large, eg Jaxen / Saxon, custom functions, attribute resolution
Milestone
Metadata
Metadata
Assignees
Labels
a:bugPMD crashes or fails to analyse a file.PMD crashes or fails to analyse a file.in:xpathRelating to xpath support at large, eg Jaxen / Saxon, custom functions, attribute resolutionRelating to xpath support at large, eg Jaxen / Saxon, custom functions, attribute resolution
Type
Fields
Give feedbackNo fields configured for issues without a type.
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
The assignment of the result of
xpathExpression::evaluatetoList<ElementNode>line 86 is unchecked, it's actually a list of the more generalItem. So when getting a node line 93, the routine will fail withClassCastExceptionif the element is not actually anElementNode.This is not completely outlandish: eg
1+1is 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