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 positives due to ignoring field accesses from inner classes #459

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

False positives due to ignoring field accesses from inner classes #459

nmatt opened this issue Jan 21, 2024 · 0 comments

Comments

@nmatt
Copy link

nmatt commented Jan 21, 2024

Field accesses from inner classes aren't correctly considered. This happens with sb-contrib version 7.6.4 (current release).

Example code:

public final class Example
{
    private final Map<String, String> map = new HashMap<>();

    public Example(String value) { map.put("foo", value); }
    
    public final class Inner
    {
        public String foo() { return map.get("foo"); }
    }
}

This incorrectly reports the bugs DMC_DUBIOUS_MAP_COLLECTION, FCBL_FIELD_COULD_BE_LOCAL, and WOC_WRITE_ONLY_COLLECTION_FIELD.

The same code without the inner class does not report these bugs:

public final class Example
{
    private final Map<String, String> map = new HashMap<>();

    public Example(String value) { map.put("foo", value); }
    
    public String foo() { return map.get("foo"); }
}
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