fb-contrib icon indicating copy to clipboard operation
fb-contrib copied to clipboard

False positives due to ignoring field accesses from inner classes

Open nmatt opened this issue 1 year ago • 0 comments

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"); }
}

nmatt avatar Jan 21 '24 22:01 nmatt