On Wed, 2 Jun 2021 11:34:18 GMT, Peter Levart <plev...@openjdk.org> wrote:
>> test/jdk/java/lang/annotation/AnnotationType/AnnotationTypeChangedToRuntimeTest.java >> line 81: >> >>> 79: " should not be visible at runtime"); >>> 80: } >>> 81: } >> >> I'm trying to understand why the case of >> `TestTask.class.getDeclaredAnnotation(AnnA_v1.class)` is different from >> `AnnB.class.getDeclaredAnnotation(AnnA_v1.class)` ... `TestTask` and `AnnB` >> are both just types annotated with the same annotation `@AnnA_v1` ... I'll >> have to debug this to see the point (does it have something to do with the >> fact that there is circularity of annotation uses: `AnnA_v1` is annotated >> with `@AnnB` while `AnnB` is annotated with `@AnnA_v1` ? > > ...hm, it seems that mere presence of any RUNTIME annotation that was RUNTIME > already at the use compile time somehow affects -XX:+PreserveAllAnnotations > option so that now RUNTIME annotations that were CLASS annotations at use > compile time are not returned. Checking VM logic... For example, if I try this: @Retention(CLASS) public @interface AnnA_v1 {} // An alternative version of AnnA_v1 with RUNTIME retention instead. // Used to simulate separate compilation (see AltClassLoader below). @Retention(RUNTIME) public @interface AnnA_v2 {} @Retention(RUNTIME) public @interface AnnB {} @AnnA_v1 @AnnB public static class TestTask implements Runnable { @Override public void run() { AnnA_v1 ann1 = TestTask.class.getDeclaredAnnotation(AnnA_v1.class); ... then `ann1` is not returned, but if I comment out the `@AnnB` annotation use on TestTask, `ann1` is returned. ------------- PR: https://git.openjdk.java.net/jdk/pull/4280