Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 402236 - [1.8][spec] default methods in annotation types?
Summary: [1.8][spec] default methods in annotation types?
Status: RESOLVED NOT_ECLIPSE
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.3   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: BETA J8   Edit
Assignee: Srikanth Sankaran CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 401003
  Show dependency tree
 
Reported: 2013-03-03 07:31 EST by Stephan Herrmann CLA
Modified: 2013-03-03 11:09 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Stephan Herrmann CLA 2013-03-03 07:31:10 EST
JSR335 0.6.2 sect. 9.6.1 has this grammar rule:

AnnotationTypeElementDeclaration:
  InterfaceMethodModifiersopt
            Type Identifier '(' ')' Dimsopt DefaultValueopt ';'
            
This would admit a default method, yet without a body.

Javac b74 happily accepts a default method *with* body in an annotation type.

Does the spec admit the modifier because semantic analysis will always detect an error regarding a missing method body?

Shouldn't the modifier already be prohibited on annotation members?
Comment 1 Srikanth Sankaran CLA 2013-03-03 08:27:05 EST
Do you have a small test case that a lazy reader can copy/paste ?
Comment 2 Stephan Herrmann CLA 2013-03-03 09:12:40 EST
(In reply to comment #1)
> Do you have a small test case that a lazy reader can copy/paste ?

Sure:

public @interface I {
    default String m1() { return "1"; } // syntactically illegal only (?) because of method body
    default String m2(); // syntactically correct (?) but semantically illegal because default method needs a body
}
Comment 3 Srikanth Sankaran CLA 2013-03-03 11:04:41 EST
This rang a bell and I realized that I raised this with the spec
committee a few months ago: This is a javac bug and does not require any
action on eclipse side: See https://bugs.eclipse.org/bugs/show_bug.cgi?id=380194#c41,
Comment 4 Stephan Herrmann CLA 2013-03-03 11:09:47 EST
Thanks, that bell should have rung for me, too :)