changeset 4804:6b51827c339c

8175198: Javac incorrectly allows receiver parameters in annotation methods Reviewed-by: mcimadamore
author vromero
date Fri, 10 Mar 2017 09:52:49 -0800
parents 7888a3e99700
children 35252ae6a7d3
files src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java test/tools/javac/T8175198/AnnotationsAndFormalParamsTest.java test/tools/javac/T8175198/AnnotationsAndFormalParamsTest.out
diffstat 3 files changed, 19 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java	Thu Mar 09 23:42:32 2017 -0800
+++ b/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/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/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