From 7631a09405383f20886833ecdd94d26e4ad678c4 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Thu, 11 Aug 2022 20:32:03 +0200 Subject: [PATCH] Do not register SynthesizedAnnotation proxy for @AliasFor Closes gh-28953 --- .../aot/hint/support/RuntimeHintsUtils.java | 4 +++- .../aot/hint/support/RuntimeHintsUtilsTests.java | 9 +++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/spring-core/src/main/java/org/springframework/aot/hint/support/RuntimeHintsUtils.java b/spring-core/src/main/java/org/springframework/aot/hint/support/RuntimeHintsUtils.java index 6976b39f0491..089860a7378a 100644 --- a/spring-core/src/main/java/org/springframework/aot/hint/support/RuntimeHintsUtils.java +++ b/spring-core/src/main/java/org/springframework/aot/hint/support/RuntimeHintsUtils.java @@ -35,6 +35,7 @@ * Utility methods for runtime hints support code. * * @author Stephane Nicoll + * @author Sam Brannen * @since 6.0 */ public abstract class RuntimeHintsUtils { @@ -88,7 +89,8 @@ private static void registerAnnotation(RuntimeHints hints, Class annotationTy } private static void collectAliasedAnnotations(Set> seen, Set> types, Class annotationType) { - if (seen.contains(annotationType) || Reflective.class.equals(annotationType)) { + if (seen.contains(annotationType) || AliasFor.class.equals(annotationType) || + Reflective.class.equals(annotationType)) { return; } seen.add(annotationType); diff --git a/spring-core/src/test/java/org/springframework/aot/hint/support/RuntimeHintsUtilsTests.java b/spring-core/src/test/java/org/springframework/aot/hint/support/RuntimeHintsUtilsTests.java index 8d57da876285..6d4a3c30ffd7 100644 --- a/spring-core/src/test/java/org/springframework/aot/hint/support/RuntimeHintsUtilsTests.java +++ b/spring-core/src/test/java/org/springframework/aot/hint/support/RuntimeHintsUtilsTests.java @@ -37,6 +37,7 @@ * Tests for {@link RuntimeHintsUtils}. * * @author Stephane Nicoll + * @author Sam Brannen */ class RuntimeHintsUtilsTests { @@ -80,6 +81,14 @@ void registerAnnotationTypeProxyRegistersJdkProxies() { .hasSize(2); } + @Test // gh-28953 + void registerAnnotationForAliasForShouldNotRegisterSynthesizedAnnotationProxy() { + RuntimeHintsUtils.registerAnnotation(this.hints, AliasFor.class); + assertThat(this.hints.reflection().typeHints()).singleElement() + .satisfies(annotationHint(AliasFor.class)); + assertThat(this.hints.proxies().jdkProxies()).isEmpty(); + } + @Test void registerAnnotationTypeWhereUsedAsAMetaAnnotationRegistersHierarchy() { RuntimeHintsUtils.registerAnnotation(this.hints, RetryWithEnabledFlagInvoker.class);