When you set showClassesComplexity= false, running PMD on a large dataset will shows a big memory leak leading to OOM.
The cause is a bug in StdCyclomaticComplexityRule:
public Object visit(ASTClassOrInterfaceDeclaration node, Object data) {
if ( node.isInterface() ) {
return data;
}
entryStack.push( new Entry( node ) );
super.visit( node, data );
if ( showClassesComplexity ) {
Entry classEntry = entryStack.pop(); // <<<<<<<< THIS IS WRONG AND MUST BE BEFORE THE IF
if ( classEntry.getComplexityAverage() >= reportLevel
|| classEntry.highestDecisionPoints >= reportLevel ) {
addViolation( data, node, new String[] {
"class",
node.getImage(),
classEntry.getComplexityAverage() + " (Highest = "
+ classEntry.highestDecisionPoints + ')' } );
}
}
return data;
}
The marked pop only executes with the property true; with false the stack collects and retains all entries leading to a huge retained heap for this rule.
I will try to send a pull request this weekend to fix this.
Diff:
See PR https://github.com/pmd/pmd/pull/103
This will be fixed with PMD 5.3.8, 5.4.3 and 5.5.1 and later (for Java)
For Apex, this will be fixed with PMD 5.5.1.