Details
Description
When using a String constant as the value for an annotation groovyc errors out with the following message:
Attribute 'value' should have type java.lang.String but found type java.lang.Object in @SpringBean
I've attached sample code to reproduce. The annotation and PersonDao are regular Java classes, just as was my case when finding the bug. The PersonAction is a Groovy class.
Issue Links
- duplicates
-
GROOVY-2827
org.codehaus.groovy.ast.expr.PropertyExpression when using external constants in annotations
-
Activity
Guillaume Laforge
made changes -
| Field | Original Value | New Value |
|---|---|---|
| Fix Version/s | 1.6 [ 13832 ] | |
| Fix Version/s | 1.7-beta-1 [ 14014 ] |
blackdrag blackdrag
made changes -
| Fix Version/s | 1.6.1 [ 14852 ] | |
| Fix Version/s | 1.6 [ 13832 ] |
Guillaume Laforge
made changes -
| Fix Version/s | 1.6.2 [ 15151 ] | |
| Fix Version/s | 1.6.1 [ 14852 ] |
Guillaume Laforge
made changes -
| Fix Version/s | 1.6.3 [ 15251 ] | |
| Fix Version/s | 1.6.2 [ 15151 ] |
Guillaume Laforge
made changes -
| Fix Version/s | 1.6.3 [ 15251 ] |
Paul King
made changes -
| Link |
This issue duplicates |
Paul King
made changes -
| Assignee | Paul King [ paulk_asert ] |
Paul King
made changes -
| Attachment | groovy2827_qualified_annotation_constants.patch [ 42638 ] |
Paul King
made changes -
| Summary | Using String constant as value of Annotation causes compile error | Using referenced String constant as value of Annotation causes compile error |
Guillaume Laforge
made changes -
| Fix Version/s | 1.7-beta-x [ 15538 ] | |
| Fix Version/s | 1.7-beta-1 [ 14014 ] |
Paul King
made changes -
| Assignee | Paul King [ paulk_asert ] |
blackdrag blackdrag
made changes -
| Fix Version/s | 1.8.x [ 15750 ] | |
| Fix Version/s | 2.x [ 17013 ] | |
| Fix Version/s | 1.7.x [ 15538 ] |
As per http://www.nabble.com/Annotation-values-in-Groovy.-td20824889.html and looking at the code, it looks like annotation values in groovy can only be constant values (like Strings, classes, numbers, other annotations and enums, etc).
In this case, annotation value itself is a property expression PersonDao.DAO_ID, which is pointing to a static final String but in terms of groovy internals, it is not a constant expression but a property expression.
So, should this case be seen as a defect or as designed?