Skip to content

[apex] ExcessivePublicCount doesn't consider inner classes correctly #4509

@adangel

Description

@adangel

Affects PMD Version: 6.x

Rule: ExcessivePublicCount

Description:

The rule counts all methods of a file regardless whether they belong to the same class or not. If you have a file with multiple (inner) classes, then all classes are considered as a single class. This is wrong - the inner classes should be considered separate.

This bug has been fixed with PMD 7.0.0 already.

Found via #3123.

Code Sample demonstrating the issue:

public virtual class OuterClass {
  public virtual class InnerClass1 {
    public virtual void method1() {}
  }

  public virtual class InnerClass2 {
    public virtual void method1() {}
  }

}

Expected outcome:
PMD should count 1 method for each class. But currently, it counts 2 methods for OuterClass, which is wrong.

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:false-positivePMD flags a piece of code that is not problematic

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions