Ensure synthesized nested annotation arrays retain correct type

Prior to this commit, when a nested array of annotations was
synthesized while adapting values within an AnnotationAttributes map,
the array was improperly replaced with an array of type Annotation[]
instead of an array of the concrete annotation type, which can lead to
unexpected run-time exceptions.

This commit fixes this bug by replacing annotations in the existing
array with synthesized versions of those annotations, thereby retaining
the original array's component type.

Issue: SPR-13077
This commit is contained in:
Sam Brannen
2015-05-26 16:51:26 +02:00
parent a2f152ce8b
commit f41de12cf6
3 changed files with 88 additions and 7 deletions

View File

@@ -924,11 +924,10 @@ public abstract class AnnotationUtils {
return mappedAnnotations;
}
else {
Annotation[] synthesizedAnnotations = new Annotation[annotations.length];
for (int i = 0; i < annotations.length; i++) {
synthesizedAnnotations[i] = synthesizeAnnotation(annotations[i], annotatedElement);
annotations[i] = synthesizeAnnotation(annotations[i], annotatedElement);
}
return synthesizedAnnotations;
return annotations;
}
}