8030816: javac crashes when mixing lambdas and inner classes
Reviewed-by: jjg, jlahoda
--- a/langtools/commit.txt Wed Jan 22 12:22:23 2014 -0800
+++ b/langtools/commit.txt Wed Jan 22 21:41:50 2014 +0000
@@ -1,3 +1,2 @@
-8027477: Enable repeating annotations test cases since JDK-8004912 is fixed
-Reviewed-by: jjg, jfranck
-Contributed-by: matherey.nunez@oracle.com
+8030816: javac crashes when mixing lambdas and inner classes
+Reviewed-by: jjg, jlahoda
--- a/langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java Wed Jan 22 12:22:23 2014 -0800
+++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java Wed Jan 22 21:41:50 2014 +0000
@@ -4661,10 +4661,19 @@
private void initTypeIfNeeded(JCTree that) {
if (that.type == null) {
- that.type = syms.unknownType;
+ if (that.hasTag(METHODDEF)) {
+ that.type = dummyMethodType();
+ } else {
+ that.type = syms.unknownType;
+ }
}
}
+ private Type dummyMethodType() {
+ return new MethodType(List.<Type>nil(), syms.unknownType,
+ List.<Type>nil(), syms.methodClass);
+ }
+
@Override
public void scan(JCTree tree) {
if (tree == null) return;
@@ -4720,7 +4729,8 @@
@Override
public void visitNewClass(JCNewClass that) {
if (that.constructor == null) {
- that.constructor = new MethodSymbol(0, names.init, syms.unknownType, syms.noSymbol);
+ that.constructor = new MethodSymbol(0, names.init,
+ dummyMethodType(), syms.noSymbol);
}
if (that.constructorType == null) {
that.constructorType = syms.unknownType;
@@ -4730,22 +4740,28 @@
@Override
public void visitAssignop(JCAssignOp that) {
- if (that.operator == null)
- that.operator = new OperatorSymbol(names.empty, syms.unknownType, -1, syms.noSymbol);
+ if (that.operator == null) {
+ that.operator = new OperatorSymbol(names.empty, dummyMethodType(),
+ -1, syms.noSymbol);
+ }
super.visitAssignop(that);
}
@Override
public void visitBinary(JCBinary that) {
- if (that.operator == null)
- that.operator = new OperatorSymbol(names.empty, syms.unknownType, -1, syms.noSymbol);
+ if (that.operator == null) {
+ that.operator = new OperatorSymbol(names.empty, dummyMethodType(),
+ -1, syms.noSymbol);
+ }
super.visitBinary(that);
}
@Override
public void visitUnary(JCUnary that) {
- if (that.operator == null)
- that.operator = new OperatorSymbol(names.empty, syms.unknownType, -1, syms.noSymbol);
+ if (that.operator == null) {
+ that.operator = new OperatorSymbol(names.empty, dummyMethodType(),
+ -1, syms.noSymbol);
+ }
super.visitUnary(that);
}
@@ -4761,7 +4777,8 @@
public void visitReference(JCMemberReference that) {
super.visitReference(that);
if (that.sym == null) {
- that.sym = new MethodSymbol(0, names.empty, syms.unknownType, syms.noSymbol);
+ that.sym = new MethodSymbol(0, names.empty, dummyMethodType(),
+ syms.noSymbol);
}
if (that.targets == null) {
that.targets = List.nil();
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/T8030816/CrashLambdaExpressionWithNonAccessibleIdTest.java Wed Jan 22 21:41:50 2014 +0000
@@ -0,0 +1,22 @@
+/*
+ * @test /nodynamiccopyright/
+ * @bug 8030816
+ * @summary javac can't compile program with lambda expression
+ * @compile/fail/ref=CrashLambdaExpressionWithNonAccessibleIdTest.out -XDrawDiagnostics CrashLambdaExpressionWithNonAccessibleIdTest.java
+ */
+
+/* This test must make sure that javac won't crash when compiling lambda
+ * containing an anonymous innerclass based on an unresolvable type.
+ */
+public class CrashLambdaExpressionWithNonAccessibleIdTest {
+ void m() {
+ m1(()-> {
+ new A(){
+ public void m11() {}
+ };
+ });
+
+ }
+
+ void m1(Runnable r) {}
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/T8030816/CrashLambdaExpressionWithNonAccessibleIdTest.out Wed Jan 22 21:41:50 2014 +0000
@@ -0,0 +1,3 @@
+CrashLambdaExpressionWithNonAccessibleIdTest.java:15:35: compiler.err.missing.ret.stmt
+CrashLambdaExpressionWithNonAccessibleIdTest.java:14:17: compiler.err.cant.resolve.location: kindname.class, A, , , (compiler.misc.location: kindname.class, CrashLambdaExpressionWithNonAccessibleIdTest, null)
+2 errors