On 1/06/2021 4:20 am, Peter Levart wrote:
On Mon, 31 May 2021 12:37:55 GMT, David Holmes <david.hol...@oracle.com> wrote:
That reads backwards to me. +PreserveAllAnnotations means that CLASS
retention annotations are retained by the VM not just RUNTIME ones. So
in that sense it might be a migration aid if moving from RUNTIME to
CLASS, not CLASS to RUNTIME.
David
Ah, I know why you think that way. You think that when an annotation is migrated from
RUNTIME to CLASS retention, that some users would still want to "see" it via
reflection (at runtime)...
Yes.
No, I don't think this was the intention of the JVM option. Migrating from
RUNTIME to CLASS retention means that the ways of looking up such annotation
are shrinking. Such change to the annotation should only be attempted when
there are no more runtime lookups to support. So 1st deprecation of RUNTIME
retention on the annotation should be published, followed by change to CLASS
retention.
OTOH when CLASS retention is changing to RUNTIME, such as in this case, the
ways of looking up are widening (there is some new desire to lookup the
annotation at runtime via reflection). To facilitate that, the annotation
maintainer changes the retention to RUNTIME. But unfortunately, old uses of the
annotation are baked in the ` RuntimeInvisibleAnnotations` attributes of the
classes that were compiled with the old version of the annotation when the
retention was still CLASS. Until all such classes are recompiled, the JVM
option can be used to make such annotation usages visible at runtime. That
makes more sense to me.
That sounds like the code that wants to inspect the annotations is using
knowledge that the target classes have been updated (in terms of the
source change from CLASS to RUNTIME) but it only has access to old
binaries. That scenario doesn't really make sense to me.
In any case the operation of the flag is very simple and has no bearing
on how AnnotationParser works.
Cheers,
David
-------------
PR: https://git.openjdk.java.net/jdk/pull/4245