Skip to content

[java] AccessorMethodGeneration false positive with overloads #807

@TWiStErRob

Description

@TWiStErRob

Affects PMD Version: 5.8.1, 6.0.0 (and probably 5.5.4 upwards since the rule was introduced)

Rule: AccessorMethodGeneration

Description: overloaded method tricks the rule into thinking there will be an accessor method generated.

Code Sample demonstrating the issue:

@SuppressWarnings({"unused", "StaticMethodOnlyUsedInOneClass", "SameParameterValue", "PMD.UseUtilityClass"})
class Outer {

  static void outerMethod(int i) {
    // package private method, safe to call, and is called from Inner.f()
  }

  private static void outerMethod(String s) {
    // private method, not used anywhere, yet triggers AccessorMethodGeneration
  }

  static class Inner {
    void f() {
      outerMethod(0);
    }
  }
}

Running PMD through: Gradle (5.8.1) and CLI (6.0.0 pmd -d . -format text -R java-design)

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:false-positivePMD flags a piece of code that is not problematicin:symbol-tableAffects the symbol table code

    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