False positive for private field referring to outer class
public class Foo {
}
class Bar {
private final Foo foo; // PMD complains about unused private field
public Bar(Foo foo) {
this.foo = foo;
}
public String toString() {
return this.foo.toString();
}
}
No problem using another type
public class Foo {
}
class Bar {
private final String foo; // false positive is not reported using String
public Bar(String foo) {
this.foo = foo;
}
public String toString() {
return this.foo.toString();
}
}
No problem with another really unused field before
public class Foo {
}
class Bar {
// with this unused field PMD doesn't complain anymore about "foo" below
private String var;
private final Foo foo;
public Bar(Foo foo) {
this.foo = foo;
}
public String toString() {
return this.foo.toString();
}
}
Neither the False Positive of the first snippet nor the False Negative of the third one are reproducible under the current master branch.
Possibly, the underlaying bug was in the symbol table analysis, and fixed with PRs https://github.com/pmd/pmd/pull/242 and https://github.com/pmd/pmd/pull/258
It's also fine for me. Obviously it has been fixed. Let's close this bug report.