Skip to content

[java] Make UnusedPrivateField consider enum classes #3632

@Zustin

Description

@Zustin

Affects PMD Version:
6.39.0

Rule:
UnusedPrivateField

Please provide the rule name and a link to the rule documentation:
https://pmd.github.io/latest/pmd_rules_java_bestpractices.html#unusedprivatefield

Description:
Hi, based on the below code sample, I think PMD should report a wanrning at line 5, but it doesn't. However, variable a is a UnusedPrivateField, so I think it is a false negative. Thanks for your consideration and I am willing to help you fix this bug.

Code Sample demonstrating the issue:

class Test {
  enum EnumClass {
      subClass();
      EnumClass() {}      
      private int a;  // should report a warning here
  }
}

Expected outcome: A violation warning

PMD should report a violation at line 5, but doesn't. This is a false-negative.

Running PMD through: [Maven]

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:false-negativePMD doesn't flag a problematic piece of code

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions