JDK-8013181 : Compiler crashes (NullPointerException) trying to compile a class with a lambda
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 8
  • Priority: P3
  • Status: Resolved
  • Resolution: Duplicate
  • Submitted: 2013-04-04
  • Updated: 2013-04-27
  • Resolved: 2013-04-27
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
openjdk version  " 1.8.0-ea " 
OpenJDK Runtime Environment (build 1.8.0-ea-lambda-nightly-h2805-20130114-b73-b00)
OpenJDK 64-Bit Server VM (build 25.0-b14, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]

A DESCRIPTION OF THE PROBLEM :
The compiler crashes with a NullPointerException trying to compile the attached source code.


ERROR MESSAGES/STACK TRACES THAT OCCUR :
Information:java: An exception has occurred in the compiler (1.8.0-ea). Please file a bug at the Java Developer Connection (http://java.sun.com/webapps/bugreport)  after checking the Bug Parade for duplicates. Include your program and the following diagnostic in your report.  Thank you.
Information:java: java.lang.NullPointerException
Information:java: at com.sun.tools.javac.jvm.Code.emitop0(Code.java:538)
Information:java: at com.sun.tools.javac.jvm.Items$SelfItem.load(Items.java:367)
Information:java: at com.sun.tools.javac.jvm.Gen.genArgs(Gen.java:912)
Information:java: at com.sun.tools.javac.jvm.Gen.visitApply(Gen.java:1746)
Information:java: at com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1412)
Information:java: at com.sun.tools.javac.jvm.Gen.genExpr(Gen.java:893)
Information:java: at com.sun.tools.javac.jvm.Gen.visitAssign(Gen.java:1844)
Information:java: at com.sun.tools.javac.tree.JCTree$JCAssign.accept(JCTree.java:1619)
Information:java: at com.sun.tools.javac.jvm.Gen.visitExec(Gen.java:1694)
Information:java: at com.sun.tools.javac.tree.JCTree$JCExpressionStatement.accept(JCTree.java:1242)
Information:java: at com.sun.tools.javac.jvm.Gen.genDef(Gen.java:683)
Information:java: at com.sun.tools.javac.jvm.Gen.genStat(Gen.java:718)
Information:java: at com.sun.tools.javac.jvm.Gen.genStat(Gen.java:704)
Information:java: at com.sun.tools.javac.jvm.Gen.genStats(Gen.java:755)
Information:java: at com.sun.tools.javac.jvm.Gen.visitBlock(Gen.java:1090)
Information:java: at com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:854)
Information:java: at com.sun.tools.javac.jvm.Gen.genMethod(Gen.java:968)
Information:java: at com.sun.tools.javac.jvm.Gen.visitMethodDef(Gen.java:941)
Information:java: at com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:738)
Information:java: at com.sun.tools.javac.jvm.Gen.genClass(Gen.java:2310)
Information:java: at com.sun.tools.javac.main.JavaCompiler.genCode(JavaCompiler.java:752)
Information:java: at com.sun.tools.javac.main.JavaCompiler.generate(JavaCompiler.java:1547)
Information:java: at com.sun.tools.javac.main.JavaCompiler.generate(JavaCompiler.java:1511)
Information:java: at com.sun.tools.javac.main.JavaCompiler.compile2(JavaCompiler.java:908)
Information:java: at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:867)
Information:java: at com.sun.tools.javac.main.Main.compile(Main.java:506)
Information:java: at com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:129)
Information:java: at org.jetbrains.jps.javac.JavacMain.compile(JavacMain.java:135)
Information:java: at org.jetbrains.jps.incremental.java.JavaBuilder.compileJava(JavaBuilder.java:313)
Information:java: at org.jetbrains.jps.incremental.java.JavaBuilder.compile(JavaBuilder.java:232)
Information:java: at org.jetbrains.jps.incremental.java.JavaBuilder.build(JavaBuilder.java:145)
Information:java: at org.jetbrains.jps.incremental.IncProjectBuilder.runModuleLevelBuilders(IncProjectBuilder.java:858)
Information:java: at org.jetbrains.jps.incremental.IncProjectBuilder.runBuildersForChunk(IncProjectBuilder.java:609)
Information:java: at org.jetbrains.jps.incremental.IncProjectBuilder.buildTargetsChunk(IncProjectBuilder.java:635)
Information:java: at org.jetbrains.jps.incremental.IncProjectBuilder.buildChunkIfAffected(IncProjectBuilder.java:572)
Information:java: at org.jetbrains.jps.incremental.IncProjectBuilder.buildChunks(IncProjectBuilder.java:555)
Information:java: at org.jetbrains.jps.incremental.IncProjectBuilder.runBuild(IncProjectBuilder.java:270)
Information:java: at org.jetbrains.jps.incremental.IncProjectBuilder.build(IncProjectBuilder.java:160)
Information:java: at org.jetbrains.jps.cmdline.BuildRunner.runBuild(BuildRunner.java:118)
Information:java: at org.jetbrains.jps.cmdline.BuildSession.runBuild(BuildSession.java:193)
Information:java: at org.jetbrains.jps.cmdline.BuildSession.run(BuildSession.java:94)
Information:java: at org.jetbrains.jps.cmdline.BuildMain$MyMessageHandler$1.run(BuildMain.java:105)
Information:java: at org.jetbrains.jps.service.impl.SharedThreadPoolImpl$1.run(SharedThreadPoolImpl.java:26)
Information:java: at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
Information:java: at java.util.concurrent.FutureTask.run(FutureTask.java:262)
Information:java: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
Information:java: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
Information:java: at java.lang.Thread.run(Thread.java:722)
Information:java: Errors occurred while compiling module 'Pathfinder'
Information:Compilation completed with 1 error and 0 warnings in 1 sec
Information:1 error
Information:0 warnings
Error:java: Compilation failed: internal java compiler error

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
public interface Heuristic_Bad
{
/**
 * Return an estimated cost to move from the source to the destination point.
 */
int getEstimatedCost(AreaMap map, int srcX, int srcY, int dstX, int dstY);

/**
 * The diagonal heuristic.
 */
Heuristic_Bad DIAGONAL = (map, srcX, srcY, dstX, dstY) -> {
int dx = dstX-srcX;
if(dx < 0)
dx = -dx;

int dy = dstY-srcY;
if(dy < 0)
dy = -dy;

return Math.max(dx, dy)*5 + Math.min(dx, dy)*2;
};
}

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Replacing the lambda with an inner class makes the problem go away:

Heuristic DIAGONAL = new Heuristic()
{
public int getEstimatedCost(AreaMap map, int srcX, int srcY, int dstX, int dstY)
{
int dx = dstX-srcX;
if(dx < 0)
dx = -dx;

int dy = dstY-srcY;
if(dy < 0)
dy = -dy;

return Math.max(dx, dy)*5 + Math.min(dx, dy)*2;
}
};
Comments
Duplicate of JDK-8006140
27-04-2013

That might already be fixed.
27-04-2013