1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Attr.java Fri May 23 16:27:22 2014 +0100 1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java Tue May 27 21:15:06 2014 +0100 1.3 @@ -4671,16 +4671,30 @@ 1.4 private void initTypeIfNeeded(JCTree that) { 1.5 if (that.type == null) { 1.6 if (that.hasTag(METHODDEF)) { 1.7 - that.type = dummyMethodType(); 1.8 + that.type = dummyMethodType((JCMethodDecl)that); 1.9 } else { 1.10 that.type = syms.unknownType; 1.11 } 1.12 } 1.13 } 1.14 1.15 + /* Construct a dummy method type. If we have a method declaration, 1.16 + * and the declared return type is void, then use that return type 1.17 + * instead of UNKNOWN to avoid spurious error messages in lambda 1.18 + * bodies (see:JDK-8041704). 1.19 + */ 1.20 + private Type dummyMethodType(JCMethodDecl md) { 1.21 + Type restype = syms.unknownType; 1.22 + if (md != null && md.restype.hasTag(TYPEIDENT)) { 1.23 + JCPrimitiveTypeTree prim = (JCPrimitiveTypeTree)md.restype; 1.24 + if (prim.typetag == VOID) 1.25 + restype = syms.voidType; 1.26 + } 1.27 + return new MethodType(List.<Type>nil(), restype, 1.28 + List.<Type>nil(), syms.methodClass); 1.29 + } 1.30 private Type dummyMethodType() { 1.31 - return new MethodType(List.<Type>nil(), syms.unknownType, 1.32 - List.<Type>nil(), syms.methodClass); 1.33 + return dummyMethodType(null); 1.34 } 1.35 1.36 @Override