Fix merged annotation attributes regression

Commit d6768ccc18 introduced a regression in the support for merging
annotation attributes in a multi-level annotation hierarchy.

This commit addresses that issue by ensuring that a merged annotation
is once again synthesized if a meta-annotation in the annotation
hierarchy declares attributes that override attributes in the target
annotation.

Closes gh-28716
This commit is contained in:
Sam Brannen
2022-06-28 14:22:53 +02:00
parent 9868c28c73
commit 622fc3edf7
2 changed files with 75 additions and 8 deletions

View File

@@ -330,11 +330,11 @@ final class TypeMappedAnnotation<A extends Annotation> extends AbstractMergedAnn
@SuppressWarnings("unchecked")
protected A createSynthesizedAnnotation() {
// Check root annotation
if (isTargetAnnotation(this.rootAttributes) && isNotSynthesizable((Annotation) this.rootAttributes)) {
if (isTargetAnnotation(this.rootAttributes) && !isSynthesizable((Annotation) this.rootAttributes)) {
return (A) this.rootAttributes;
}
// Check meta-annotation
else if (isTargetAnnotation(this.mapping.getAnnotation()) && isNotSynthesizable(this.mapping.getAnnotation())) {
else if (isTargetAnnotation(this.mapping.getAnnotation()) && !isSynthesizable(this.mapping.getAnnotation())) {
return (A) this.mapping.getAnnotation();
}
return SynthesizedMergedAnnotationInvocationHandler.createProxy(this, getType());
@@ -351,14 +351,25 @@ final class TypeMappedAnnotation<A extends Annotation> extends AbstractMergedAnn
}
/**
* Determine if the supplied annotation has already been synthesized or if the
* mapped annotation is not {@linkplain AnnotationTypeMapping#isSynthesizable()
* synthesizable} in general.
* Determine if the supplied annotation has not already been synthesized
* <strong>and</strong> whether the mapped annotation is a composed annotation
* that needs to have its attributes merged or the mapped annotation is
* {@linkplain AnnotationTypeMapping#isSynthesizable() synthesizable} in general.
* @param annotation the annotation to check
* @since 5.3.22
*/
private boolean isNotSynthesizable(Annotation annotation) {
return (annotation instanceof SynthesizedAnnotation || !this.mapping.isSynthesizable());
private boolean isSynthesizable(Annotation annotation) {
// Already synthesized?
if (annotation instanceof SynthesizedAnnotation) {
return false;
}
// Is this a mapped annotation for a composed annotation, and are there
// annotation attributes (mirrors) that need to be merged?
if (getDistance() > 0 && this.resolvedMirrors.length > 0) {
return true;
}
// Is the mapped annotation itself synthesizable?
return this.mapping.isSynthesizable();
}
@Override