RFR: JDK-8191981: javac crash when detecting lambda candidates
Jan Lahoda
jan.lahoda at oracle.com
Tue Nov 28 11:46:20 UTC 2017
Hi,
Consider this code:
---
public class LambdaWithMethod {
public static void run(Runnable r) {
run(new Runnable() {
public void run() {
put(get());
}
});
}
private static String get() { return null; }
private static void put(String i) {}
}
---
When detecting lambda candidates, this crashes javac (please see the bug
for full exception):
---
$ javac -XDfind=lambda /tmp/LambdaWithMethod.java
[snip]
java.lang.AssertionError: Analyzer error when processing: [snip]
at jdk.compiler/com.sun.tools.javac.util.Assert.error(Assert.java:162)
at
jdk.compiler/com.sun.tools.javac.comp.Analyzer.doAnalysis(Analyzer.java:562)
[snip]
---
The underlying exception is:
---
java.lang.ClassCastException:
jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodInvocation cannot
be cast to jdk.compiler/com.sun.tools.javac.tree.JCTree$JCLambda
at
jdk.compiler/com.sun.tools.javac.comp.ArgumentAttr$ExplicitLambdaType.dup(ArgumentAttr.java:456)
at
jdk.compiler/com.sun.tools.javac.comp.ArgumentAttr.processArg(ArgumentAttr.java:237)
[snip]
---
(Full exception in the bug.)
The problem appears to be that when the trial lambda node (that replaces
the anonymous class) is created, there is no explicit position set, and
so the last position set is used. And the ArgumentAttr.argumentTypeCache
uses the position as key, and so the value for "get()" is (appears to
be) used for the lambda, which leads to the crash.
Bug; https://bugs.openjdk.java.net/browse/JDK-8191981
Proposed patch: http://cr.openjdk.java.net/~jlahoda/8191981/webrev.00
How does this look?
Thanks,
Jan
More information about the compiler-dev
mailing list