spotbugs / spotbugs

SpotBugs is FindBugs' successor. A tool for static analysis to look for bugs in Java code.

Home Page:https://spotbugs.github.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

False positive: UMAC_UNCALLABLE_METHOD_OF_ANONYMOUS_CLASS

clo-vis opened this issue · comments

import java.util.stream.Stream;

class Test {
    public static void main(String[] args) {
        record Foo(int a) {
            int aPlus1() {
                return a + 1;
            }

            int aPlus2() {
                return a + 2;
            }
        }
        var foo = new Foo(1);
        Stream.of(foo).mapToInt(Foo::aPlus1).forEach(System.out::println);
        Stream.of(foo).mapToInt(r -> r.aPlus2()).forEach(System.out::println);
    }
}

Warning: Uncallable method Test$1Foo.aPlus1() defined in anonymous class [Scary(5), High confidence]

But:

  1. There is no anonymous class (all classes in the example have a name)
  2. Both methods aPlus2 and aPlus1 are callable and are called.

Sorry, just saw I already opened a similar bug 6 years ago.
#682