Given the following code, a SingularField error is reported, however, the field is used.
PMD 4.3 bundled in Sonar 3.2
public enum MyEnum {
A("a"),
B("b");
private final String description; // <-- SingularField reported private MyEnum(String description) { this.description = description; } public static MyEnum byDescription(String description) { for (MyEnum myEnum : values()) { if (myEnum.description.equals(description)) { // <--- USED HERE return myEnum; } } return null; }
}
Thank you for your bug report.
I can reproduce it with the latest PMD 5 version and will try to fix it soon.
I've fixed it with this commit:
https://github.com/pmd/pmd/commit/28b37d6767160ce2676f9ffe4ec21d25aea7a82b
It will be shipped either with a 5.0.1 release or with the next 5.1.0.