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:
Sam Brannen
2022-06-25 19:04:21 +02:00
parent faf20b7a5a
commit d6768ccc18
3 changed files with 58 additions and 10 deletions

View File

@@ -73,8 +73,8 @@ class BootstrapUtilsTests {
assertThatIllegalStateException()
.isThrownBy(() -> resolveTestContextBootstrapper(bootstrapContext))
.withMessageContaining("Configuration error: found multiple declarations of @BootstrapWith")
.withMessageContaining(FooBootstrapper.class.getCanonicalName())
.withMessageContaining(BarBootstrapper.class.getCanonicalName());
.withMessageContaining(FooBootstrapper.class.getSimpleName())
.withMessageContaining(BarBootstrapper.class.getSimpleName());
}
@Test