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

Jaroslav Tulach github.com+26887752+jaroslavtulach at openjdk.java.net
Mon May 31 06:11:18 UTC 2021


On Sun, 30 May 2021 23:03:55 GMT, David Holmes <david.holmes at oracle.com> wrote:

> But we should add in some tests.

Right, I was surprised by missing tests as well. I've just created a _"standalone"_ commit 0f689ea  that adds such test and also shows the way I am currently using the `-XX:+PreserveAllAnnotations` flag. It [requires some tricks](https://github.com/openjdk/jdk/pull/4245/files#r642231785) with `ClassLoader` and bytecode manipulation to change the retention to `RUNTIME` and then (in combination with `-XX:+PreserveAllAnnotations`) the annotation is accessible.

The test in 0f689ea is _"standalone"_ - e.g. it can be merged without my other changes. However I continue to hope the change in `Class.getAnnotation` could get in: the `-XX:+PreserveAllAnnotation` option hasn't caused any issues since Java 5 - this is the first improvement ever requested. Possibly also the last one - tests are written & the functionality works - what else could one want?

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

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


More information about the hotspot-runtime-dev mailing list