Evolution of annotation types - reducing set of supported targets
Alex Buckley
alex.buckley at oracle.com
Wed Jun 28 18:19:42 UTC 2017
On 6/28/2017 1:23 AM, Gunnar Morling wrote:
> I'm trying to figure whether removing an element type from an
> annotation's set of supported targets is considered to break binary
> compatibility or not.
Binary compatibility concerns the JVM's ability to continue to link the
changed class. Since linking does not care about annotations, any change
to an annotation's type is binary compatible. Your issue is nothing to
do with binary compatibility, but rather with the specified behavior of
the Core Reflection API when an annotation's presence is out of sync
with the annotation's type. I believe the Core Reflection API is
designed to be extremely forgiving in these circumstances.
Alex
> Some quick testing indicates it's non-breaking: I have an annotation
> which in v1 supports {TYPE,FIELD} and in v2 just {FIELD}. Linking
> against v2, I still can retrieve the annotation from a type definition
> in a binary compiled against v1.
>
> Is there some official confirmation of this? Esp. is it guaranteed
> that the annotation can be retrieved from the now unsupported location
> or could there theoretically be a runtime which performs a check of
> the supported targets? I was looking in JLS 13.5.7. "Evolution of
> Annotation Types", but couldn't find anything.
More information about the compiler-dev
mailing list