Skip to content

Commit 79b5dd3

Browse files
committed
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
1 parent 60784e6 commit 79b5dd3

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/properties/AnnotationsPropertySource.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,11 @@ private List<Annotation> getMergedAnnotations(Class<?> root, Class<?> source) {
9090
if (annotations != null) {
9191
for (Annotation annotation : annotations) {
9292
if (!AnnotationUtils.isInJavaLangAnnotationPackage(annotation)) {
93-
mergedAnnotations
94-
.add(findMergedAnnotation(root, annotation.annotationType()));
93+
Annotation mergedAnnotation = findMergedAnnotation(root,
94+
annotation.annotationType());
95+
if (mergedAnnotation != null) {
96+
mergedAnnotations.add(mergedAnnotation);
97+
}
9598
}
9699
}
97100
}

0 commit comments

Comments
 (0)