Method lookup error causes NullPointerException with nested lambdas

Issue #202 new
Jesper Öqvist created an issue

ExtendJ 8.0.1-174-g53debda Java SE 8

The following test case should generate an error message instead of a NullPointerException:

import java.util.function.Function;

interface StringTransformer {
  String transform(String str, Function<String, String> fun);
  String replaceWords(String str, Function<String, String> fun);

public class Lambda2 {
  public String replace(String input, StringTransformer transformer) {
    return transform(input, str -> replaceWords(str, word -> "foo"));

The transform method access is incorrect - it should be qualified by transformer. However, this test case should result in a nice error message instead of the following:

Fatal exception:
        at org.extendj.ast.LambdaExpr.toClass(
        at org.extendj.ast.LambdaExpr.anonymousDecl(
        at org.extendj.ast.LambdaExpr.Define_enclosingLambdaType(
        at org.extendj.ast.ASTNode.Define_enclosingLambdaType(
        at org.extendj.ast.InferredParameterDeclaration.enclosingLambdaType(
        at org.extendj.ast.InferredParameterDeclaration.hostType(
        at org.extendj.ast.VarAccess.nameProblems(
        at org.extendj.ast.VarAccess.contributeTo_CompilationUnit_problems(
        at org.extendj.ast.CompilationUnit.problems_compute(
        at org.extendj.ast.CompilationUnit.problems(
        at org.extendj.ast.CompilationUnit.errors(
        at org.extendj.ast.Frontend.processCompilationUnit(
        at org.extendj.JavaCompiler.processCompilationUnit(
        at org.extendj.JavaCompiler.main(
        at org.jastadd.extendj.JavaCompiler.main(

Comments (2)

  1. Jesper Öqvist reporter

    The original test case is: jsr335/lambda/err_01f.

    Added another test (jsr335/lambda/err_02f), which does not use type inference:

    import java.util.function.Function;
    public interface Test {
      String transform(String in, Function<String, String> fun);
      default void prepend(String string) {
        transform(missing, t -> t);
  2. Jesper Öqvist reporter

    The problem is caused by LambdaExpr.targetInterface() being nullable, but used without a null guard in creating an anonymous class for lambda expressions. See java8/frontend/LambdaAnonymousDecl.jrag:

      syn nta ClassInstanceExpr LambdaExpr.toClass() =
          new ClassInstanceExpr(
              new List<Expr>(),
              new Opt<TypeDecl>(buildAnonymousDecl()));
  3. Log in to comment