Ensure meta-annotations are not unnecessarily synthesized
Prior to this commit, meta-annotations were unnecessarily synthesized when attempting to synthesize a MergedAnnotation retrieved via the MergedAnnotations.from(AnnotatedElement, ...).get(<annotationType>) API. This is a regression in our merged annotation support that was introduced when the MergedAnnotations API replaced our previous support. This commit fixes this by revising the logic in TypeMappedAnnotation's createSynthesizedAnnotation() method so that a meta-annotation is returned unmodified if it is not synthesizable. This commit also updates BootstrapUtilsTests, since @BootstrapWith should never have been synthesized, and Class#getCanonicalName() is only used in the toString() implementation of an annotation synthesized by Spring or normal annotations on Java 19+ (see https://bugs.openjdk.org/browse/JDK-8281462). Closes gh-28704
This commit is contained in:
@@ -1420,6 +1420,17 @@ class MergedAnnotationsTests {
|
||||
assertThat(generatedValue).isSameAs(synthesizedGeneratedValue);
|
||||
}
|
||||
|
||||
@Test
|
||||
void synthesizeShouldNotSynthesizeNonsynthesizableAnnotationsWhenUsingMergedAnnotationsFromApi() {
|
||||
MergedAnnotations mergedAnnotations = MergedAnnotations.from(SecurityConfig.class);
|
||||
|
||||
EnableWebSecurity enableWebSecurity = mergedAnnotations.get(EnableWebSecurity.class).synthesize();
|
||||
assertThat(enableWebSecurity).isNotInstanceOf(SynthesizedAnnotation.class);
|
||||
|
||||
EnableGlobalAuthentication enableGlobalAuthentication = mergedAnnotations.get(EnableGlobalAuthentication.class).synthesize();
|
||||
assertThat(enableGlobalAuthentication).isNotInstanceOf(SynthesizedAnnotation.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* If an attempt is made to synthesize an annotation from an annotation instance
|
||||
* that has already been synthesized, the original synthesized annotation should
|
||||
@@ -3097,6 +3108,25 @@ class MergedAnnotationsTests {
|
||||
return 42L;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mimics org.springframework.security.config.annotation.authentication.configuration.EnableGlobalAuthentication
|
||||
*/
|
||||
@Retention(RUNTIME)
|
||||
@interface EnableGlobalAuthentication {
|
||||
}
|
||||
|
||||
/**
|
||||
* Mimics org.springframework.security.config.annotation.web.configuration.EnableWebSecurity
|
||||
*/
|
||||
@Retention(RUNTIME)
|
||||
@EnableGlobalAuthentication
|
||||
@interface EnableWebSecurity {
|
||||
}
|
||||
|
||||
@EnableWebSecurity
|
||||
static class SecurityConfig {
|
||||
}
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@interface TestConfiguration {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user