8175198: Javac incorrectly allows receiver parameters in annotation methods
authorvromero
Fri, 10 Mar 2017 09:52:49 -0800
changeset 44194 c868c8c24e18
parent 44193 11902232a629
child 44195 5860769fe2f4
8175198: Javac incorrectly allows receiver parameters in annotation methods Reviewed-by: mcimadamore
langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java
langtools/test/tools/javac/T8175198/AnnotationsAndFormalParamsTest.java
langtools/test/tools/javac/T8175198/AnnotationsAndFormalParamsTest.out
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java	Thu Mar 09 23:42:32 2017 -0800
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java	Fri Mar 10 09:52:49 2017 -0800
@@ -974,8 +974,11 @@
 
             ClassSymbol owner = env.enclClass.sym;
             if ((owner.flags() & ANNOTATION) != 0 &&
-                    tree.params.nonEmpty())
-                log.error(tree.params.head.pos(),
+                    (tree.params.nonEmpty() ||
+                    tree.recvparam != null))
+                log.error(tree.params.nonEmpty() ?
+                        tree.params.head.pos() :
+                        tree.recvparam.pos(),
                         "intf.annotation.members.cant.have.params");
 
             // Attribute all value parameters.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/T8175198/AnnotationsAndFormalParamsTest.java	Fri Mar 10 09:52:49 2017 -0800
@@ -0,0 +1,11 @@
+/*
+ * @test /nodynamiccopyright/
+ * @bug 8175198
+ * @summary Javac incorrectly allows receiver parameters in annotation methods
+ * @compile/fail/ref=AnnotationsAndFormalParamsTest.out -XDrawDiagnostics -Werror -Xlint:unchecked AnnotationsAndFormalParamsTest.java
+ */
+
+@interface AnnotationsAndFormalParamsTest {
+    int value(int i);
+    int foo(AnnotationsAndFormalParamsTest this);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/T8175198/AnnotationsAndFormalParamsTest.out	Fri Mar 10 09:52:49 2017 -0800
@@ -0,0 +1,3 @@
+AnnotationsAndFormalParamsTest.java:9:19: compiler.err.intf.annotation.members.cant.have.params
+AnnotationsAndFormalParamsTest.java:10:44: compiler.err.intf.annotation.members.cant.have.params
+2 errors