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)...

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.

-------------

PR: https://git.openjdk.java.net/jdk/pull/4245

Reply via email to