From e7a6b8c2606c5ee92a4db257c1593d1e2739ebda Mon Sep 17 00:00:00 2001 From: Dennis Kieselhorst Date: Mon, 31 Jul 2017 10:26:05 +0200 Subject: [PATCH] Avoid NPE in PropertyMappingContextCustomizer See gh-9914 --- .../PropertyMappingContextCustomizer.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) 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 f6dcc3f594..c45a05d585 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();