RFR: JDK-8267936: PreserveAllAnnotations option doesn't expose the annotation to Java code

Jaroslav Tulach github.com+26887752+jaroslavtulach at openjdk.java.net
Sat May 29 07:20:37 UTC 2021


On Fri, 28 May 2021 12:56:39 GMT, Jaroslav Tulach <github.com+26887752+JaroslavTulach at openjdk.org> wrote:

> This PR exposes runtime invisible annotations via `Class.getAnnotation` when `-XX:+PreserveAllAnnotations` option is passed to the JVM.
> 
> Existing `-XX:+PreserveAllAnnotations` option can be very useful for code that needs to access annotations with `RetentionPolicy.CLASS` without the need to parse the .class files manually. While the RuntimeInvisibleAnnotations are kept in the runtime, they are not visible via java.lang.reflect API. I assume that's just an omission.
> 
> This PR provides a test and a single line fix that makes `-XX:+PreserveAllAnnotations` useful in cooperation with `Class.getAnnotation(...)`.

There is an existing failing `test/jdk/java/lang/annotation/AnnotationType/AnnotationTypeRuntimeAssumptionTest.java` test - probably I should modify the fix to only skip the `Retention.RUNTIME` check when the `-XX:+PreserveAllAnnotations` option is on. Suggestions how to properly check value of `-XX:+PreserveAllAnnotations` from `sun/reflect/annotation/AnnotationParser.java ` welcomed.

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

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


More information about the core-libs-dev mailing list