JDK-8175198 : Javac incorrectly allows receiver parameters in annotation methods
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 9
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • Submitted: 2017-02-17
  • Updated: 2017-05-17
  • Resolved: 2017-03-10
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 10 JDK 9
10Fixed 9 b161Fixed
Sub Tasks
JDK-8179979 :  
Description
Receiver parameters are not allowed in annotation methods. Javac should produce an error

@interface MethodRun {
    int value(MethodRun this);
}
Comments
Attn: docs For the release notes: javac was erroneously accepting receiver parameters in annotations methods. This implies that tests cases like the one below were being accepted: @interface MethodRun { int value(MethodRun this); } The JLS 8, see JLS8 9.6.1, doesn't allow any formal parameter in annotation methods, this extends to receiver parameters. More specifically, the grammar for annotation types does not allow arbitrary method declarations, instead allowing only AnnotationTypeElementDeclarations. The allowed syntax is: AnnotationTypeElementDeclaration: {AnnotationTypeElementModifier} UnannType Identifier ( ) [Dims] [DefaultValue]; Note that nothing is allowed between the parentheses.
16-03-2017

More specifically, the grammar for annotation types does not allow arbitrary method declarations, instead allowing only AnnotationTypeElementDeclarations (JLS 9.6.1). Here's the syntax: AnnotationTypeElementDeclaration: {AnnotationTypeElementModifier} UnannType Identifier ( ) [Dims] [DefaultValue] ; Note that nothing is allowed between the parens.
07-03-2017