JDK-6505167 : Annotations syntax error in JLS 9.7
  • Type: Bug
  • Component: specification
  • Sub-Component: language
  • Affected Version: 7
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2006-12-15
  • Updated: 2014-02-26
  • Resolved: 2011-07-21
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 7
7 rcFixed
Related Reports
Relates :  
Description
ElementValue in JLS 9.7/18.1 allows ConditionalExpression or Annotation or ElementValueArrayInitializer. The use of ConditionalExpression is confusing because the text on page 283 limits primitive/String-typed element values to being constant expressions. Could the ElementValue grammar use ConstantExpression?

Comments
EVALUATION The grammar of ConstantExpression is just Expression, which is way too loose for the desired semantics, so 15.28 heavily restricts which operators can appear in the Expression. The production that best encodes these restrictions is ConditionalExpression. Therefore, any time that a "constant expression" is the desired syntax, it is appropriate to use ConditionalExpression rather than ConstantExpression. And that's what the grammars in 9.7/18.1 do for primitive/String-typed element values. If 9.7/18.1 used ConstantExpression, then any old Expression would be syntactically acceptable and 9.7 would have to repeat the constraints from 15.28 on legitimate operators. The JSR175 draft acknowledged the surprising use of ConditionalExpression: "A ConditionalExpression is simply an expression without assignments, and not necessarily an expression involving the conditional operator (? :).)" A discussion point about this on page 283 wouldn't hurt. (One might ask whether ConstantExpression should be redefined to accept ConditionalExpression, rather than Expression. The answer is probably "yes".) Further errors on page 283: - "T is an array type E[] and either: ... V is an ElementValue that is commensurate with ***E***." - "V is an ElementValueArrayInitializer and each ***ElementValue*** in V..."
15-12-2006