JDK-8225771 : Three nested lambdas break compiler
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 8
  • Priority: P3
  • Status: Closed
  • Resolution: Won't Fix
  • OS: windows_10
  • CPU: x86_64
  • Submitted: 2019-06-13
  • Updated: 2019-06-14
  • Resolved: 2019-06-14
Description
ADDITIONAL SYSTEM INFORMATION :
Windows 10, JDK 1.8_212

A DESCRIPTION OF THE PROBLEM :
With nested lambda compiler crash with a NullPointerException!

I did several attempts with different version(1.8.111, 1.8.152, 1.8.162, 1.8.211) and on different environment(Windows, Mac).

I tried with CMD using mvn clean compile or via intelliJ using maven plugin.


My stackoverflow question: https://stackoverflow.com/questions/56566180/java-8-nested-lambdas-break-compiler/56566397#56566397

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Create a 3 nested lambda and compile 

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Project compiled
ACTUAL -
An exception has occurred in the compiler (1.8.0_211). Please file a bug against the Java compiler via the Java bug reporting page (http://bugrepor
t.java.com) after checking the Bug Database (http://bugs.java.com) for duplicates. Include your program and the following diagnostic in your report
. Thank you.
java.lang.NullPointerException
        at com.sun.tools.javac.jvm.Code.emitop0(Code.java:559)
        at com.sun.tools.javac.jvm.Items$SelfItem.load(Items.java:367)
        at com.sun.tools.javac.jvm.Gen.genArgs(Gen.java:966)
        at com.sun.tools.javac.jvm.Gen.visitApply(Gen.java:1842)
        at com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1465)
        at com.sun.tools.javac.jvm.Gen.genExpr(Gen.java:947)
        at com.sun.tools.javac.jvm.Gen.visitAssign(Gen.java:1982)
        at com.sun.tools.javac.tree.JCTree$JCAssign.accept(JCTree.java:1686)
        at com.sun.tools.javac.jvm.Gen.genExpr(Gen.java:947)
        at com.sun.tools.javac.jvm.Gen.visitExec(Gen.java:1781)
        at com.sun.tools.javac.tree.JCTree$JCExpressionStatement.accept(JCTree.java:1296)
        at com.sun.tools.javac.jvm.Gen.genDef(Gen.java:737)
        at com.sun.tools.javac.jvm.Gen.genStat(Gen.java:772)
        at com.sun.tools.javac.jvm.Gen.genStat(Gen.java:758)
        at com.sun.tools.javac.jvm.Gen.genStats(Gen.java:809)
        at com.sun.tools.javac.jvm.Gen.visitBlock(Gen.java:1157)
        at com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:909)
        at com.sun.tools.javac.jvm.Gen.genDef(Gen.java:737)
        at com.sun.tools.javac.jvm.Gen.genStat(Gen.java:772)
        at com.sun.tools.javac.jvm.Gen.genMethod(Gen.java:1031)
        at com.sun.tools.javac.jvm.Gen.visitMethodDef(Gen.java:994)
        at com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:778)
        at com.sun.tools.javac.jvm.Gen.genDef(Gen.java:737)
        at com.sun.tools.javac.jvm.Gen.genClass(Gen.java:2454)
        at com.sun.tools.javac.main.JavaCompiler.genCode(JavaCompiler.java:745)
        at com.sun.tools.javac.main.JavaCompiler.generate(JavaCompiler.java:1572)
        at com.sun.tools.javac.main.JavaCompiler.generate(JavaCompiler.java:1536)
        at com.sun.tools.javac.main.JavaCompiler.compile2(JavaCompiler.java:901)
        at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:860)
        at com.sun.tools.javac.main.Main.compile(Main.java:523)
        at com.sun.tools.javac.api.JavacTaskImpl.doCall(JavacTaskImpl.java:129)
        at com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:138)
        at org.codehaus.plexus.compiler.javac.JavaxToolsCompiler.compileInProcess(JavaxToolsCompiler.java:125)
        at org.codehaus.plexus.compiler.javac.JavacCompiler.performCompile(JavacCompiler.java:171)
        at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:886)
        at org.apache.maven.plugin.compiler.CompilerMojo.execute(CompilerMojo.java:129)
        at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:154)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:146)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81)
        at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:309)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:194)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:107)
        at org.apache.maven.cli.MavenCli.execute(MavenCli.java:955)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:290)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:194)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)

---------- BEGIN SOURCE ----------
import java.util.function.Function;
import java.util.function.Supplier;

public class Test {

    public static Function<String, Supplier<String>> A = aVal -> new Supplier<String>() {

        @Override
        public String get() {
            return B.apply(aVal).get();
        }

        private Function<String, Supplier<String>> B = bVal -> new Supplier<String>() {
            @Override
            public String get() {
                return C.apply(bVal).get();
            }

            private Function<String, Supplier<String>> C = cVal -> new Supplier<String>() {
                @Override
                public String get() {
                    return cVal;
                }
            };
        };
    };
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Move the most nested lambda above, so removing one nested level.

FREQUENCY : always



Comments
This issue is already fixed in 9 and higher versions. 8uxx - Fail 9 GA - Pass 11 - Pass 13 - Pass Kindly upgrade your java to use JDK11 [1], to avoid this issue [1] https://www.oracle.com/technetwork/java/javase/downloads/jdk11-downloads-5066655.html
14-06-2019