Running the java-controversial ruleset, specifically DataflowAnomalyAnalysis on source which has nested conditionals, loops, and sentinel values causes PMD to hang indefinintely or until it throws an OutOfMemoryException.
The last line of debugging output is:
Processing continueBreakReturnStack elements
Starting continueBreakReturnStack processing loop
ENTRY
RETURN
Completed continueBreakReturnStack processing loop
RETURN
Could not find class <class>, due to: java.lang.ClassNotFoundException: <class>
Then the PMD process will just hang until forcibly terminated.
I created a contrivied example source file (LoopTest.java; attached) which causes the halting. I've also attached the debug output (pmd.out) of running the command:
pmd.bat -f xml -R java-controversial -D -d LoopTest.java -r ec2test.out
Removing a loop, conditional, or sentinel assignment will result in PMD exiting cleanly. So my guess is that the complex structure of the looping and branching is causing problems for DataflowAnomalyAnalysis.
I forgot to note that I created a custom ruleset which excluded DataflowAnomalyAnalysis, and PMD exits cleanly when using it.
<ruleset name="controversial-sans-dataflow" xmlns="http://pmd.sf.net/ruleset/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd" xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd"> <description>Java Controversial ruleset without DataflowAnomalyAnalysis</description> <rule ref="rulesets/java/controversial.xml"> <exclude name="DataflowAnomalyAnalysis"/> </rule> </ruleset>The debug output is the list of loaded rules, "Processing <file>", and then the error "Could not find class <class>...".
I'll stop the endless loop within PMD now, so that it won't hang anymore
However, due to [#1383] your for-each-loops will be flagged - the DataflowAnomalyAnalysis can't deal with for-each-loops yet.
https://github.com/pmd/pmd/commit/0f48fd501d350570f6d285042e1f858b42c4a04b
Related
Issues: #1383