8131742: Syntactically meaningless code accepted by javac
Summary: Receiver parameter logic for type annotations should be disabled when parsing lambda formals
Reviewed-by: jlahoda
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java Thu Jul 30 13:21:01 2015 +0100
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java Thu Jul 30 13:24:35 2015 +0100
@@ -2985,7 +2985,7 @@
name = token.name();
nextToken();
} else {
- if (allowThisIdent) {
+ if (allowThisIdent && !lambdaParameter) {
JCExpression pn = qualident(false);
if (pn.hasTag(Tag.IDENT) && ((JCIdent)pn).name != names._this) {
name = ((JCIdent)pn).name;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/lambda/8131742/T8131742.java Thu Jul 30 13:24:35 2015 +0100
@@ -0,0 +1,9 @@
+/*
+ * @test /nodynamiccopyright/
+ * @bug 8131742
+ * @summary Syntactically meaningless code accepted by javac
+ * @compile/fail/ref=T8131742.out -XDrawDiagnostics T8131742.java
+ */
+class T8131742 {
+ static Runnable r = (__GAR BAGE__.this) -> { };
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/lambda/8131742/T8131742.out Thu Jul 30 13:24:35 2015 +0100
@@ -0,0 +1,4 @@
+T8131742.java:8:38: compiler.err.expected3: ',', ')', '['
+T8131742.java:8:39: compiler.err.this.as.identifier
+T8131742.java:8:43: compiler.err.expected: ';'
+3 errors