Skip to content

NullAway crashes when encountering a lambda that takes an argument nested in an anonymous inner class #1156

@agrieve

Description

@agrieve

Tested with 0.12.4.

Foo.java:24: error: An unhandled exception was thrown by the Error Prone static analysis plugin.
        Foo foo = new Foo(x -> x);
                          ^
     Please report this at https://github.com/google/error-prone/issues/new and include the following:

     error-prone version: 2.36.0
     BugPattern: NullAway
     Stack Trace:
     com.google.common.base.VerifyException
  	at com.google.common.base.Verify.verify(Verify.java:102)
  	at com.uber.nullaway.generics.GenericsChecks.getTypeForSymbol(GenericsChecks.java:774)
  	at com.uber.nullaway.generics.GenericsChecks.getGenericMethodParameterNullness(GenericsChecks.java:1000)
  	at com.uber.nullaway.NullAway.checkParamOverriding(NullAway.java:806)
  	at com.uber.nullaway.NullAway.matchLambdaExpression(NullAway.java:997)
  	at com.google.errorprone.scanner.ErrorProneScanner.processMatchers(ErrorProneScanner.java:509)
  	at com.google.errorprone.scanner.ErrorProneScanner.visitLambdaExpression(ErrorProneScanner.java:775)
  	at com.google.errorprone.scanner.ErrorProneScanner.visitLambdaExpression(ErrorProneScanner.java:170)
  	at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCLambda.accept(JCTree.java:2038)
  	at jdk.compiler/com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:92)
  	at com.google.errorprone.scanner.Scanner.scan(Scanner.java:74)
  	at com.google.errorprone.scanner.Scanner.scan(Scanner.java:48)
  	at jdk.compiler/com.sun.source.util.TreeScanner.scan(TreeScanner.java:110)
  	at jdk.compiler/com.sun.source.util.TreeScanner.scanAndReduce(TreeScanner.java:118)
  	at jdk.compiler/com.sun.source.util.TreeScanner.visitNewClass(TreeScanner.java:610)
  	at com.google.errorprone.scanner.ErrorProneScanner.visitNewClass(ErrorProneScanner.java:860)
  	at com.google.errorprone.scanner.ErrorProneScanner.visitNewClass(ErrorProneScanner.java:170)
  	at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCNewClass.accept(JCTree.java:1934)
  	at jdk.compiler/com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:92)
  	at com.google.errorprone.scanner.Scanner.scan(Scanner.java:74)
  	at com.google.errorprone.scanner.Scanner.scan(Scanner.java:48)
...

Here's a repro:

import org.jspecify.annotations.NullMarked;
import java.util.function.Function;
import java.util.function.Supplier;

@NullMarked
public class Foo implements Supplier<Integer> {
  public Foo(Function<Integer, Integer> func) {
  }

  @Override
  public Integer get() {
    return 0;
  }

  public static void test() {
    new Supplier<Boolean>() {
      @Override
      public Boolean get() {
        Foo foo = new Foo(x -> 1);
        return true;
      }
    };
  }
}
  • The crash does not happen if Foo accepts a Supplier (() -> 0)
  • The crash does not happen if Foo foo = new Foo(x -> 1); appears directly within test() instead

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions