fb-contrib
fb-contrib copied to clipboard
False positive FCBL_FIELD_COULD_BE_LOCAL for private field of nested class
Accesses to private fields of a nested class from the containing class (and possibly vice-versa?) are not considered, leading to false positives. This happens with sb-contrib version 7.6.4 (current release).
Example code:
public final class Example
{
public final Type type;
public final String id;
public Example(Type type, String id)
{
this.type = requireNonNull(type);
this.id = requireNonNull(id);
}
@Override
public String toString()
{
return type.displayName + " <" + id + ">";
}
public enum Type
{
FOO("Foolicious"),
BAR("Barocious");
private final String displayName;
private Type(String displayName)
{
this.displayName = displayName;
}
};
}
This reports FCBL_FIELD_COULD_BE_LOCAL for Type.displayName
.
Making the field package-private or public does not report the bug. Similarly, when adding a Type::toString
returning displayName
, the bug is not reported.
(In this example, the rationale is that Type
should be public. but we don't want to directly expose its display name, which is an implementation detail for use in the containing class.)