# HG changeset patch # User vromero # Date 1489168369 28800 # Node ID c868c8c24e18979690bd240d2dc9f7b4bb848295 # Parent 11902232a6294229e90053db11e0a94c0cf08aaf 8175198: Javac incorrectly allows receiver parameters in annotation methods Reviewed-by: mcimadamore diff -r 11902232a629 -r c868c8c24e18 langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java --- 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. diff -r 11902232a629 -r c868c8c24e18 langtools/test/tools/javac/T8175198/AnnotationsAndFormalParamsTest.java --- /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); +} diff -r 11902232a629 -r c868c8c24e18 langtools/test/tools/javac/T8175198/AnnotationsAndFormalParamsTest.out --- /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