From e7a6b8c2606c5ee92a4db257c1593d1e2739ebda Mon Sep 17 00:00:00 2001 From: Dennis Kieselhorst Date: Mon, 31 Jul 2017 10:26:05 +0200 Subject: [PATCH 1/3] 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 f6dcc3f594b..c45a05d5850 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(); From 25d0cc167e7b4582841a6b1fcfa9198c3a9882eb Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Wed, 9 Aug 2017 11:41:39 +0100 Subject: [PATCH 2/3] Polish "Avoid NPE in PropertyMappingContextCustomizer" See gh-9914 --- .../properties/PropertyMappingContextCustomizer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 c45a05d5850..1c811cb0c7f 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 @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. From 7967c64d65b643812afd332d1d389d85008630d9 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Wed, 9 Aug 2017 11:42:38 +0100 Subject: [PATCH 3/3] Avoid NPE in AnnotationsPropertySource if getAnnotations returns null Closes gh-9914 --- .../properties/AnnotationsPropertySource.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) 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 083250b9013..dcd5bd0befd 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 @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -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;