Commit 79b5dd3a authored by Phillip Webb's avatar Phillip Webb

Protect against NPE when collecting annotations

Update `AnnotationsPropertySource` to ensure that `null` results from
`findMergedAnnotation` are not added to the annotation list.

Prior to this commit, if `findMergedAnnotation` returned `null` then
`AnnotationsPropertySource.collectProperties` would throw an NPE.
Although `findMergedAnnotation` should never return `null`, we're
best off being defensive so that bugs such as SPR-17495 won't cause
problems.

Closes gh-15175
parent 60784e63
...@@ -90,8 +90,11 @@ public class AnnotationsPropertySource extends EnumerablePropertySource<Class<?> ...@@ -90,8 +90,11 @@ public class AnnotationsPropertySource extends EnumerablePropertySource<Class<?>
if (annotations != null) { if (annotations != null) {
for (Annotation annotation : annotations) { for (Annotation annotation : annotations) {
if (!AnnotationUtils.isInJavaLangAnnotationPackage(annotation)) { if (!AnnotationUtils.isInJavaLangAnnotationPackage(annotation)) {
mergedAnnotations Annotation mergedAnnotation = findMergedAnnotation(root,
.add(findMergedAnnotation(root, annotation.annotationType())); annotation.annotationType());
if (mergedAnnotation != null) {
mergedAnnotations.add(mergedAnnotation);
}
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment