mebigfatguy / fb-contrib

a FindBugs/SpotBugs plugin for doing static code analysis for java code bases
http://fb-contrib.sf.net
GNU Lesser General Public License v2.1
157 stars 45 forks source link

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

Open nmatt opened 10 months ago

nmatt commented 10 months ago

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