diff --git a/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/properties/AnnotationsPropertySource.java b/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/properties/AnnotationsPropertySource.java index bd6696cf8f8..29df05fad0e 100644 --- a/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/properties/AnnotationsPropertySource.java +++ b/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/properties/AnnotationsPropertySource.java @@ -85,10 +85,13 @@ public class AnnotationsPropertySource extends EnumerablePropertySource private List getMergedAnnotations(Class root, Class source) { List mergedAnnotations = new ArrayList<>(); - for (Annotation annotation : AnnotationUtils.getAnnotations(source)) { - if (!AnnotationUtils.isInJavaLangAnnotationPackage(annotation)) { - mergedAnnotations - .add(findMergedAnnotation(root, annotation.annotationType())); + Annotation[] annotations = AnnotationUtils.getAnnotations(source); + if (annotations != null) { + for (Annotation annotation : annotations) { + if (!AnnotationUtils.isInJavaLangAnnotationPackage(annotation)) { + mergedAnnotations + .add(findMergedAnnotation(root, annotation.annotationType())); + } } } return mergedAnnotations; diff --git a/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/properties/PropertyMappingContextCustomizer.java b/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/properties/PropertyMappingContextCustomizer.java index 8d6d05e6052..dd98f974bcc 100644 --- a/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/properties/PropertyMappingContextCustomizer.java +++ b/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/properties/PropertyMappingContextCustomizer.java @@ -79,12 +79,15 @@ class PropertyMappingContextCustomizer implements ContextCustomizer { Set> components = new LinkedHashSet<>(); Set> propertyMappings = new LinkedHashSet<>(); while (beanClass != null) { - for (Annotation annotation : AnnotationUtils.getAnnotations(beanClass)) { - if (isAnnotated(annotation, Component.class)) { - components.add(annotation.annotationType()); - } - if (isAnnotated(annotation, PropertyMapping.class)) { - propertyMappings.add(annotation.annotationType()); + Annotation[] annotations = AnnotationUtils.getAnnotations(beanClass); + if (annotations != null) { + for (Annotation annotation : annotations) { + if (isAnnotated(annotation, Component.class)) { + components.add(annotation.annotationType()); + } + if (isAnnotated(annotation, PropertyMapping.class)) { + propertyMappings.add(annotation.annotationType()); + } } } beanClass = beanClass.getSuperclass();