#1501 [java] [apex] CyclomaticComplexity rule causes OOM when class reporting is disabled

PMD-5.3.8
closed
PMD
3-Major
Bug
5.4.2
StdCyclomaticComplexityRule
2016-07-07
2016-07-01
No

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.

Discussion

  • Andreas Dangel

    Andreas Dangel - 2016-07-07
    • labels: --> java
    • summary: CyclomaticComplexity rule causes OOM when class reporting is disabled --> [java] CyclomaticComplexity rule causes OOM when class reporting is disabled
    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -1,6 +1,8 @@
     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;
    @@ -21,6 +23,7 @@
         }
         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.
    
     
  • Andreas Dangel

    Andreas Dangel - 2016-07-07
    • labels: java --> java, apex
    • summary: [java] CyclomaticComplexity rule causes OOM when class reporting is disabled --> [java] [apex] CyclomaticComplexity rule causes OOM when class reporting is disabled
    • Milestone: New Tickets --> PMD-5.5.1
     
  • Andreas Dangel

    Andreas Dangel - 2016-07-07
    • status: open --> closed
    • assigned_to: Andreas Dangel
    • Milestone: PMD-5.5.1 --> PMD-5.3.8
     
  • Andreas Dangel

    Andreas Dangel - 2016-07-07

    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.

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks