Mon, 27 Jan 2014 21:15:39 +0000
8030816: javac crashes when mixing lambdas and inner classes
Reviewed-by: jjg, jlahoda
1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Attr.java Mon Jan 27 21:05:58 2014 +0000 1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java Mon Jan 27 21:15:39 2014 +0000 1.3 @@ -1,5 +1,5 @@ 1.4 /* 1.5 - * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. 1.6 + * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved. 1.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.8 * 1.9 * This code is free software; you can redistribute it and/or modify it 1.10 @@ -4653,10 +4653,19 @@ 1.11 1.12 private void initTypeIfNeeded(JCTree that) { 1.13 if (that.type == null) { 1.14 - that.type = syms.unknownType; 1.15 + if (that.hasTag(METHODDEF)) { 1.16 + that.type = dummyMethodType(); 1.17 + } else { 1.18 + that.type = syms.unknownType; 1.19 + } 1.20 } 1.21 } 1.22 1.23 + private Type dummyMethodType() { 1.24 + return new MethodType(List.<Type>nil(), syms.unknownType, 1.25 + List.<Type>nil(), syms.methodClass); 1.26 + } 1.27 + 1.28 @Override 1.29 public void scan(JCTree tree) { 1.30 if (tree == null) return; 1.31 @@ -4712,7 +4721,8 @@ 1.32 @Override 1.33 public void visitNewClass(JCNewClass that) { 1.34 if (that.constructor == null) { 1.35 - that.constructor = new MethodSymbol(0, names.init, syms.unknownType, syms.noSymbol); 1.36 + that.constructor = new MethodSymbol(0, names.init, 1.37 + dummyMethodType(), syms.noSymbol); 1.38 } 1.39 if (that.constructorType == null) { 1.40 that.constructorType = syms.unknownType; 1.41 @@ -4722,22 +4732,28 @@ 1.42 1.43 @Override 1.44 public void visitAssignop(JCAssignOp that) { 1.45 - if (that.operator == null) 1.46 - that.operator = new OperatorSymbol(names.empty, syms.unknownType, -1, syms.noSymbol); 1.47 + if (that.operator == null) { 1.48 + that.operator = new OperatorSymbol(names.empty, dummyMethodType(), 1.49 + -1, syms.noSymbol); 1.50 + } 1.51 super.visitAssignop(that); 1.52 } 1.53 1.54 @Override 1.55 public void visitBinary(JCBinary that) { 1.56 - if (that.operator == null) 1.57 - that.operator = new OperatorSymbol(names.empty, syms.unknownType, -1, syms.noSymbol); 1.58 + if (that.operator == null) { 1.59 + that.operator = new OperatorSymbol(names.empty, dummyMethodType(), 1.60 + -1, syms.noSymbol); 1.61 + } 1.62 super.visitBinary(that); 1.63 } 1.64 1.65 @Override 1.66 public void visitUnary(JCUnary that) { 1.67 - if (that.operator == null) 1.68 - that.operator = new OperatorSymbol(names.empty, syms.unknownType, -1, syms.noSymbol); 1.69 + if (that.operator == null) { 1.70 + that.operator = new OperatorSymbol(names.empty, dummyMethodType(), 1.71 + -1, syms.noSymbol); 1.72 + } 1.73 super.visitUnary(that); 1.74 } 1.75 1.76 @@ -4753,7 +4769,8 @@ 1.77 public void visitReference(JCMemberReference that) { 1.78 super.visitReference(that); 1.79 if (that.sym == null) { 1.80 - that.sym = new MethodSymbol(0, names.empty, syms.unknownType, syms.noSymbol); 1.81 + that.sym = new MethodSymbol(0, names.empty, dummyMethodType(), 1.82 + syms.noSymbol); 1.83 } 1.84 if (that.targets == null) { 1.85 that.targets = List.nil();
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/test/tools/javac/T8030816/CrashLambdaExpressionWithNonAccessibleIdTest.java Mon Jan 27 21:15:39 2014 +0000 2.3 @@ -0,0 +1,22 @@ 2.4 +/* 2.5 + * @test /nodynamiccopyright/ 2.6 + * @bug 8030816 2.7 + * @summary javac can't compile program with lambda expression 2.8 + * @compile/fail/ref=CrashLambdaExpressionWithNonAccessibleIdTest.out -XDrawDiagnostics CrashLambdaExpressionWithNonAccessibleIdTest.java 2.9 + */ 2.10 + 2.11 +/* This test must make sure that javac won't crash when compiling lambda 2.12 + * containing an anonymous innerclass based on an unresolvable type. 2.13 + */ 2.14 +public class CrashLambdaExpressionWithNonAccessibleIdTest { 2.15 + void m() { 2.16 + m1(()-> { 2.17 + new A(){ 2.18 + public void m11() {} 2.19 + }; 2.20 + }); 2.21 + 2.22 + } 2.23 + 2.24 + void m1(Runnable r) {} 2.25 +}
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/test/tools/javac/T8030816/CrashLambdaExpressionWithNonAccessibleIdTest.out Mon Jan 27 21:15:39 2014 +0000 3.3 @@ -0,0 +1,3 @@ 3.4 +CrashLambdaExpressionWithNonAccessibleIdTest.java:15:35: compiler.err.missing.ret.stmt 3.5 +CrashLambdaExpressionWithNonAccessibleIdTest.java:14:17: compiler.err.cant.resolve.location: kindname.class, A, , , (compiler.misc.location: kindname.class, CrashLambdaExpressionWithNonAccessibleIdTest, null) 3.6 +2 errors