Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8333313

NullPointerException in lambda instantiating an inner local class in prologue

XMLWordPrintable

    • b25
    • b04

      After integration of JEP 482, one JCK test failed with java.lang.NullPointerException: Cannot read field "sym" because "this.lvar[1]" is null

      The test case:

      interface Foo {
          void foo();
      }

      public class Main {
          static int check = 0;

          class Test {
              Test() {}
              Test(int a) {
                  class InnerLocal {
                      int a = 1;
                  }
                  Foo lmb = () -> {
                      Main.check = new InnerLocal() {
                          public int a() {
                              return this.a;
                          }
                      }.a();
                  };
                  lmb.foo();
                  this();
              }
          }

      }

      java --enable-preview --source 23 ~/IdeaProjects/Test/src/Main.java
      An exception has occurred in the compiler (23-ea). Please file a bug against the Java compiler via the Java bug reporting page (https://bugreport.java.com) after checking the Bug Database (https://bugs.java.com) for duplicates. Include your program, the following diagnostic, and the parameters passed to the Java compiler in your report. Thank you.
      java.lang.NullPointerException: Cannot read field "sym" because "this.lvar[1]" is null
      at jdk.compiler/com.sun.tools.javac.jvm.Code.emitop0(Code.java:575)
      at jdk.compiler/com.sun.tools.javac.jvm.Items$LocalItem.load(Items.java:399)
      at jdk.compiler/com.sun.tools.javac.jvm.Gen.genArgs(Gen.java:884)
      at jdk.compiler/com.sun.tools.javac.jvm.Gen.visitNewClass(Gen.java:2041)
      at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCNewClass.accept(JCTree.java:1912)
      at jdk.compiler/com.sun.tools.javac.jvm.Gen.genExpr(Gen.java:859)
      at jdk.compiler/com.sun.tools.javac.jvm.Gen.visitSelect(Gen.java:2390)
      at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCFieldAccess.accept(JCTree.java:2570)
      at jdk.compiler/com.sun.tools.javac.jvm.Gen.genExpr(Gen.java:859)
      at jdk.compiler/com.sun.tools.javac.jvm.Gen.visitApply(Gen.java:1929)
      at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1857)
      at jdk.compiler/com.sun.tools.javac.jvm.Gen.genExpr(Gen.java:859)
      at jdk.compiler/com.sun.tools.javac.jvm.Gen.visitAssign(Gen.java:2097)
      at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCAssign.accept(JCTree.java:2101)
      at jdk.compiler/com.sun.tools.javac.jvm.Gen.genExpr(Gen.java:859)
      at jdk.compiler/com.sun.tools.javac.jvm.Gen.visitExec(Gen.java:1802)
      at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCExpressionStatement.accept(JCTree.java:1644)
      at jdk.compiler/com.sun.tools.javac.jvm.Gen.genDef(Gen.java:588)
      at jdk.compiler/com.sun.tools.javac.jvm.Gen.genStat(Gen.java:623)
      at jdk.compiler/com.sun.tools.javac.jvm.Gen.genStat(Gen.java:609)
      at jdk.compiler/com.sun.tools.javac.jvm.Gen.genStats(Gen.java:660)
      at jdk.compiler/com.sun.tools.javac.jvm.Gen.internalVisitBlock(Gen.java:1121)
      at jdk.compiler/com.sun.tools.javac.jvm.Gen.visitBlock(Gen.java:1085)
      at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:1133)
      at jdk.compiler/com.sun.tools.javac.jvm.Gen.genDef(Gen.java:588)
      at jdk.compiler/com.sun.tools.javac.jvm.Gen.genStat(Gen.java:623)
      at jdk.compiler/com.sun.tools.javac.jvm.Gen.genMethod(Gen.java:949)
      at jdk.compiler/com.sun.tools.javac.jvm.Gen.visitMethodDef(Gen.java:912)
      at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:957)
      at jdk.compiler/com.sun.tools.javac.jvm.Gen.genDef(Gen.java:588)
      at jdk.compiler/com.sun.tools.javac.jvm.Gen.genClass(Gen.java:2494)
      at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.genCode(JavaCompiler.java:770)
      at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.generate(JavaCompiler.java:1703)
      at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.generate(JavaCompiler.java:1671)
      at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:977)
      at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.lambda$doCall$0(JavacTaskImpl.java:104)
      at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.invocationHelper(JavacTaskImpl.java:152)
      at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.doCall(JavacTaskImpl.java:100)
      at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:94)
      at jdk.compiler/com.sun.tools.javac.launcher.MemoryContext.compileProgram(MemoryContext.java:125)
      at jdk.compiler/com.sun.tools.javac.launcher.SourceLauncher.run(SourceLauncher.java:150)
      at jdk.compiler/com.sun.tools.javac.launcher.SourceLauncher.main(SourceLauncher.java:78)

      java --version
      openjdk 23-ea 2024-09-17
      OpenJDK Runtime Environment (build 23-ea+25-2094)
      OpenJDK 64-Bit Server VM (build 23-ea+25-2094, mixed mode, sharing)

      The following test is affected:
      lang/ICLS/icls159/icls15901m62/icls15901m62.html

            vromero Vicente Arturo Romero Zaldivar
            eananeva Ella Ananeva
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: