<html>
  <head>

    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <p>Hello,</p>
    <p>A few hours ago, I reported a compiler bug through the Bug Report
      form at bugreport.java.com. Since then, a developer friend who
      discovered the issue dug into it and found a bit more information.</p>
    <p>The bug number given to me by the form was 9075022. To summarize
      the issue, for reference: if a local class is defined in a method
      which uses a parameter from said method (whether in methods or
      field initializers), and within the method is a lambda which
      contains a (local) subclass of that local class, then attempting
      to instantiate the local class or local subclass within the lambda
      causes a compiler crash. <br>
    </p>
    <p>Here is example source code which shows the crash when tried to
      be compiled by Java 12 and later:</p>
    <pre>public abstract class JavacBug {

    public abstract void consume(Runnable r);

    public void doThing(String parameter) {
        class LocalClass {

            @Override
            public String toString() {
                return parameter;
            }
        }

        consume(() -> {
            class LambdaLocalClass extends LocalClass {
            }

            new LocalClass();
        });
    }
}
</pre>
    <p>Compiling the above results in the following crash on Java 21 EA
      (similar stacktraces are shown for all other affected Java
      versions):</p>
    <pre>java.lang.AssertionError
        at jdk.compiler/com.sun.tools.javac.util.Assert.error(Assert.java:155)
        at jdk.compiler/com.sun.tools.javac.util.Assert.check(Assert.java:46)
        at jdk.compiler/com.sun.tools.javac.jvm.Items$LocalItem.<init>(Items.java:392)
        at jdk.compiler/com.sun.tools.javac.jvm.Items.makeLocalItem(Items.java:133)
        at jdk.compiler/com.sun.tools.javac.jvm.Gen.visitIdent(Gen.java:2327)
        at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCIdent.accept(JCTree.java:2681)
        at jdk.compiler/com.sun.tools.javac.jvm.Gen.genExpr(Gen.java:884)
        at jdk.compiler/com.sun.tools.javac.jvm.Gen.genArgs(Gen.java:909)
        at jdk.compiler/com.sun.tools.javac.jvm.Gen.visitApply(Gen.java:1925)
        at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1817)
        at jdk.compiler/com.sun.tools.javac.jvm.Gen.genExpr(Gen.java:884)
        at jdk.compiler/com.sun.tools.javac.jvm.Gen.visitExec(Gen.java:1793)
        at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCExpressionStatement.accept(JCTree.java:1604)
        at jdk.compiler/com.sun.tools.javac.jvm.Gen.genDef(Gen.java:613)
        at jdk.compiler/com.sun.tools.javac.jvm.Gen.genStat(Gen.java:648)
        at jdk.compiler/com.sun.tools.javac.jvm.Gen.genStat(Gen.java:634)
        at jdk.compiler/com.sun.tools.javac.jvm.Gen.genStats(Gen.java:685)
        at jdk.compiler/com.sun.tools.javac.jvm.Gen.doVisitBlock(Gen.java:1127)
        at jdk.compiler/com.sun.tools.javac.jvm.Gen.visitBlock(Gen.java:1120)
        at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:1088)
        at jdk.compiler/com.sun.tools.javac.jvm.Gen.genDef(Gen.java:613)
        at jdk.compiler/com.sun.tools.javac.jvm.Gen.genStat(Gen.java:648)
        at jdk.compiler/com.sun.tools.javac.jvm.Gen.genMethod(Gen.java:974)
        at jdk.compiler/com.sun.tools.javac.jvm.Gen.visitMethodDef(Gen.java:937)
        at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:912)
        at jdk.compiler/com.sun.tools.javac.jvm.Gen.genDef(Gen.java:613)
        at jdk.compiler/com.sun.tools.javac.jvm.Gen.genClass(Gen.java:2471)
        at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.genCode(JavaCompiler.java:751)
        at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.generate(JavaCompiler.java:1681)
        at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.generate(JavaCompiler.java:1649)
        at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:960)
        at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:317)
        at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:176)
        at jdk.compiler/com.sun.tools.javac.Main.compile(Main.java:64)
        at jdk.compiler/com.sun.tools.javac.Main.main(Main.java:50)
</pre>
    <p>As described in my original bug report, the issue exists in Java
      12 and above.</p>
    <p>As mentioned above, my developer friend dug into the issue and
      bisected JDK 12 to find the commit that introduced the regression,
      which seems to be <a moz-do-not-send="true"
href="https://github.com/openjdk/jdk12/commit/1ed6b88a9965efb2992f158bdb96b86d38cb9a45"
        class="moz-txt-link-freetext">https://github.com/openjdk/jdk12/commit/1ed6b88a9965efb2992f158bdb96b86d38cb9a45</a>.</p>
    <p>I hope this information will be useful in debugging and fixing
      the issue.</p>
    <p>(As an aside, it does seem a bit unfriendly that there is no way
      to add on additional information to a report after being submitted
      through the online form, nor is the report made accessible to the
      reporter, whether through the site or even a copy sent to the
      reporter's email address. Where would I bring this up for further
      discussion?)<br>
    </p>
    <p>Regards,<br>
      Arnold (@sciwhiz12)<br>
    </p>
  </body>
</html>