[
https://issues.apache.org/jira/browse/FELIX-5404?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15769506#comment-15769506
]
Julian Sedding commented on FELIX-5404:
---------------------------------------
[~djencks] do I understand you correctly, that you are saying that it is
correct that no {{<property/>}} tag is generated for annotation methods with a
default value that is an empty array? I'm still reading up on the spec, so I
assume your interpretation to be correct.
However, if this is the case, I would argue that the SCR spec is in conflict
with the Java spec section 9.6.2\[0\], which requires an "annotation type
element" (i.e. a method) to be "commensurate" with the default value.
Commensurate (in this context) is defined as follows (my words with details
omitted, see section 9.7.1\[1\] for details):
- An array type is commensurate with a value if the array's component type is
commensurate with each of its values.
- A non-array is commensurate with a value if the value is assignment
compatible and *not null*
Since we are not using annotations exactly the way they were designed, I would
argue that this implies that a method with a default value *must not* return
null. In my books, that would certainly be in violation of the principle of
least surprise.
Furthermore, the Java spec says about default values in section 9.6.2\[0\]:
bq. Default values are not compiled into annotations, but rather applied
dynamically at the time annotations are read. Thus, changing a default value
affects annotations even in classes that were compiled before the change was
made (presuming these annotations lack an explicit value for the defaulted
element).
While we are certainly not applying the default values dynamically, one could
argue that we're ok here, because an annotation type with changed default
values is typically deployed within a bundle that also contains a descriptor
generated from the annotation type, and thus the descriptor contains the
changed default values.
\[0\] http://docs.oracle.com/javase/specs/jls/se8/html/jls-9.html#jls-9.6.2
\[1\] http://docs.oracle.com/javase/specs/jls/se8/html/jls-9.html#jls-9.7.1
> Annotation configurations default values are not considered
> -----------------------------------------------------------
>
> Key: FELIX-5404
> URL: https://issues.apache.org/jira/browse/FELIX-5404
> Project: Felix
> Issue Type: Bug
> Components: Declarative Services (SCR)
> Affects Versions: scr-2.0.6
> Reporter: Julian Sedding
> Assignee: Carsten Ziegeler
> Priority: Minor
> Attachments: FELIX-5404-integration-test-jsedding.patch,
> FELIX-5404-jsedding.patch
>
>
> When an annotation is used to configure an SCR component (as per DS 1.3), the
> annotation's default values are not considered.
> This can lead to the odd situation that an annotation method with a default
> value returns null. I'm not sure if this violates a contract or another,
> however, my IDE complains when I do a null check.
> I think it would be the right thing to do to return the default value if no
> value is explicitly configured.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)