teavm
teavm copied to clipboard
Switch statement causes compiler to throw NPE
I ran into a case where a switch statement causes an NPE in compile. I simplified it down to a minimal case. I'm not sure what version of teavm I'm running, but it's only a couple months old. In my version I added a missing "break;" statement back and it avoided the problem.
jeff
import org.teavm.jso.dom.events.*;
/** Compile crash test: Causes compiler to crash with NPE. */ public class CrashTest {
public static void main(String args[]) { handleEvent(null); }
public static void handleEvent(Event e)
{
Runnable run = null;
switch(e.getType()) {
case "mousemove": run = () -> handleEvent((MouseEvent)e);
}
}
}
prompt> java -cp /Users/jeff/SnapCode/TVTests/bin/:/Users/jeff/SnapCode/SnapTea/lib/teavm-cli.jar org.teavm.cli.TeaVMRunner CrashTest INFO: Running TeaVM Analyzing classes...java.lang.NullPointerException at org.teavm.dependency.DataFlowGraphBuilder.assign(DataFlowGraphBuilder.java:142) at org.teavm.model.InstructionReadVisitor.visit(InstructionReadVisitor.java:81) at org.teavm.model.instructions.AssignInstruction.acceptVisitor(AssignInstruction.java:43) at org.teavm.model.BasicBlock.readAllInstructions(BasicBlock.java:314) at org.teavm.dependency.DataFlowGraphBuilder.buildMapping(DataFlowGraphBuilder.java:79) at org.teavm.dependency.DependencyGraphBuilder.buildGraph(DependencyGraphBuilder.java:73) at org.teavm.dependency.PreciseDependencyAnalyzer.processMethod(PreciseDependencyAnalyzer.java:34) at org.teavm.dependency.DependencyAnalyzer.lambda$scheduleMethodAnalysis$8(DependencyAnalyzer.java:509) at org.teavm.dependency.DependencyAnalyzer.processQueue(DependencyAnalyzer.java:667) at org.teavm.dependency.DependencyAnalyzer.processDependencies(DependencyAnalyzer.java:694) at org.teavm.vm.TeaVM.build(TeaVM.java:372) at org.teavm.tooling.TeaVMTool.generate(TeaVMTool.java:379) at org.teavm.cli.TeaVMRunner.build(TeaVMRunner.java:369) at org.teavm.cli.TeaVMRunner.buildNonInteractive(TeaVMRunner.java:354) at org.teavm.cli.TeaVMRunner.runAll(TeaVMRunner.java:317) at org.teavm.cli.TeaVMRunner.main(TeaVMRunner.java:154) prompt>
I believe that this issue may be related to the report #500 . Although the cause here is more subtle.
In this case, the break
keyword solves the error because it prevents the first lambda expression to be replaced with the following one. Without it, the first lambda is not in use and it causes the NullPointerException
.