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

WOC_WRITE_ONLY_COLLECTION_LOCAL false positive if collection is read in lambda #451

Closed donalmurtagh closed 12 months ago

donalmurtagh commented 12 months ago

This was introduced when I upgraded sb-contrib from 7.6.0 to 7.6.1 and spotbugs from 5.2.3 to 5.2.4. It looks like a regression of #39

public class FbFail {

    private final List<String> list = List.of("foo", "bar");

    public void fail() {
        list.forEach(System.out::println);
        /*
        for (var obj : list) {
            System.out.println(obj);
        }
         */
    }
}

The forEach fails the WOC_WRITE_ONLY_COLLECTION_LOCAL check, but if it is replaced by the for-loop the check passes.

mebigfatguy commented 12 months ago

oops, not sure what happened. targetted at 7.6.2