Do not register SynthesizedAnnotation proxy for @AliasFor

Closes gh-28953
This commit is contained in:
Sam Brannen 2022-08-11 20:32:03 +02:00
parent 0207f3a55f
commit 7631a09405
2 changed files with 12 additions and 1 deletions

View File

@ -35,6 +35,7 @@ import org.springframework.core.annotation.SynthesizedAnnotation;
* Utility methods for runtime hints support code.
*
* @author Stephane Nicoll
* @author Sam Brannen
* @since 6.0
*/
public abstract class RuntimeHintsUtils {
@ -88,7 +89,8 @@ public abstract class RuntimeHintsUtils {
}
private static void collectAliasedAnnotations(Set<Class<?>> seen, Set<Class<?>> 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);

View File

@ -37,6 +37,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* Tests for {@link RuntimeHintsUtils}.
*
* @author Stephane Nicoll
* @author Sam Brannen
*/
class RuntimeHintsUtilsTests {
@ -80,6 +81,14 @@ class RuntimeHintsUtilsTests {
.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);