javac throwing NPE at com.sun.tools.javac.comp.Flow$FlowAnalyzer.visitApply
Filipp Zhinkin
filipp.zhinkin at oracle.com
Mon Nov 19 01:55:06 PST 2012
Hi,
I've found that following code force javac to throw NullPointerException:
public class NPE {
public static void main(String args[]) {
// "cannot find symbol" error is expected
new Integer(0).forEach(System.out::println);
}
}
$java -version
openjdk version "1.8.0-ea"
OpenJDK Runtime Environment (build
1.8.0-ea-lambda-nightly-h1745-20121105-b64-b00)
OpenJDK Server VM (build 25.0-b05, mixed mode)
$javac NPE.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.
java.lang.NullPointerException
at
com.sun.tools.javac.comp.Flow$FlowAnalyzer.visitApply(Flow.java:1197)
at
com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1395)
at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
at com.sun.tools.javac.tree.TreeScanner.visitExec(TreeScanner.java:173)
at
com.sun.tools.javac.tree.JCTree$JCExpressionStatement.accept(JCTree.java:1226)
at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:57)
at com.sun.tools.javac.comp.Flow$FlowAnalyzer.visitBlock(Flow.java:960)
at com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:839)
at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
at
com.sun.tools.javac.comp.Flow$FlowAnalyzer.visitMethodDef(Flow.java:927)
at com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:723)
at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
at
com.sun.tools.javac.comp.Flow$FlowAnalyzer.visitClassDef(Flow.java:890)
at com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:645)
at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
at
com.sun.tools.javac.comp.Flow$FlowAnalyzer.analyzeTree(Flow.java:1277)
at
com.sun.tools.javac.comp.Flow$FlowAnalyzer.analyzeTree(Flow.java:1267)
at com.sun.tools.javac.comp.Flow.analyzeTree(Flow.java:210)
at com.sun.tools.javac.main.JavaCompiler.flow(JavaCompiler.java:1297)
at com.sun.tools.javac.main.JavaCompiler.flow(JavaCompiler.java:1271)
at
com.sun.tools.javac.main.JavaCompiler.compile2(JavaCompiler.java:911)
at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:870)
at com.sun.tools.javac.main.Main.compile(Main.java:441)
at com.sun.tools.javac.main.Main.compile(Main.java:358)
at com.sun.tools.javac.main.Main.compile(Main.java:347)
at com.sun.tools.javac.main.Main.compile(Main.java:338)
at com.sun.tools.javac.Main.compile(Main.java:76)
at com.sun.tools.javac.Main.main(Main.java:61)
With method reference replaced by lambda expression javac will report
semantic error as expected:
public class SemError {
public static void main(String args[]) {
new Integer(0).forEach((x) -> { System.out.println(x); });
}
}
$javac SemError.java
SemError.java:3: error: cannot find symbol
new Integer(0).forEach((x) -> { System.out.println(x); });
^
symbol: method forEach(<none>)
location: class Integer
1 error
Hope it will be useful.
Filipp.
More information about the lambda-dev
mailing list