The current PLSQL XPath rules do not specify an XPath version and default to XPath version 1.0, thereby using JaxenXPathRuleQuery to evaluate the rules. Using this against PLSQL code results in a NullPointerException in JaxenXPathRuleQuery.evaluate at line 71.
An effective workaround is to switch to using SaxonXPathRuleQuery, by specifying version "1.0 compatibility" or "2.0" (see attached rules and log files)
<property name="version">
<value>1.0 compatibility</value>
</property>
Test Case Output
HEAPSIZE=2048m LIB_DIR=../../pmd-runtime-libs ./run.sh pmd -debug -f text -R PLSQLXPathNPE.xml -language plsql -d plsql_minimal.pkb >PLSQLXPathNPE.log 2>&1
...
...
Loaded rule XPath NPE Problem
Using PLSQL version: PLSQL
Processing /Users/sturton/Development/pmd.git/pmd/plsql_minimal.pkb
ENTRY
RETURN
ENTRY
Rule=net.sourceforge.pmd.lang.rule.XPathRule@6d481f12
Node=PrimaryExpression
RuleContext=net.sourceforge.pmd.RuleContext@73e4dd9
Rule Classname=net.sourceforge.pmd.lang.rule.XPathRule
Rule Name=XPath NPE Problem
Error while processing file: /Users/sturton/Development/pmd.git/pmd/plsql_minimal.pkb
java.lang.NullPointerException
at net.sourceforge.pmd.lang.rule.xpath.JaxenXPathRuleQuery.evaluate(JaxenXPathRuleQuery.java:71)
at net.sourceforge.pmd.lang.rule.XPathRule.evaluate(XPathRule.java:74)
at net.sourceforge.pmd.lang.plsql.rule.PLSQLRuleChainVisitor.visit(PLSQLRuleChainVisitor.java:49)
at net.sourceforge.pmd.lang.rule.AbstractRuleChainVisitor.visitAll(AbstractRuleChainVisitor.java:85)
at net.sourceforge.pmd.RuleChain.apply(RuleChain.java:66)
at net.sourceforge.pmd.RuleSets.apply(RuleSets.java:122)
at net.sourceforge.pmd.SourceCodeProcessor.processSource(SourceCodeProcessor.java:150)
at net.sourceforge.pmd.SourceCodeProcessor.processSourceCode(SourceCodeProcessor.java:80)
at net.sourceforge.pmd.SourceCodeProcessor.processSourceCode(SourceCodeProcessor.java:47)
at net.sourceforge.pmd.processor.PmdRunnable.call(PmdRunnable.java:78)
at net.sourceforge.pmd.processor.PmdRunnable.call(PmdRunnable.java:25)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
/Users/sturton/Development/pmd.git/pmd/plsql_minimal.pkb - Error while processing /Users/sturton/Development/pmd.git/pmd/plsq
NPE avoided by adding minimal XPathHandler to PLSQLHandler
The source code fragment works, making the change in the master branch,
But you must indicate property version in the xpath rule property of the xml ruleset:
The change to be added inside net.sourceforge.pmd.lang.plsql.PLSQLHandler is:
Last edit: andres hurtado 2014-02-28
PLSQL Rules have already been modified and committed (in c593de73dc38e47906c0a837804b788ca8641889 [c593de7] )
Last edit: Andreas Dangel 2014-04-12
Thank you Stuart!
I've cherry-picked your commits and this bug will be fixed with the next release.
There was one additional step needed to get XPath 1.0 (with Jaxon) working: The root node of the plsql AST hierarchy must be marked with the RootNode interface, so that the DocumentNavigator works. In the case of plsql, it's the class ASTInput which serves as the root node.