Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

False positive FCBL_FIELD_COULD_BE_LOCAL for private field of nested class #460

Open
nmatt opened this issue Jan 21, 2024 · 0 comments
Open

Comments

@nmatt
Copy link

nmatt commented Jan 21, 2024

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.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants