Merge pull request #9914 from Dennis Kieselhorst
* gh-9914: Avoid NPE in AnnotationsPropertySource if getAnnotations returns null Polish "Avoid NPE in PropertyMappingContextCustomizer" Avoid NPE in PropertyMappingContextCustomizer
This commit is contained in:
commit
dc33ec1ad9
|
|
@ -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,12 +85,15 @@ public class AnnotationsPropertySource extends EnumerablePropertySource<Class<?>
|
|||
|
||||
private List<Annotation> getMergedAnnotations(Class<?> root, Class<?> source) {
|
||||
List<Annotation> mergedAnnotations = new ArrayList<Annotation>();
|
||||
for (Annotation annotation : AnnotationUtils.getAnnotations(source)) {
|
||||
Annotation[] annotations = AnnotationUtils.getAnnotations(source);
|
||||
if (annotations != null) {
|
||||
for (Annotation annotation : annotations) {
|
||||
if (!AnnotationUtils.isInJavaLangAnnotationPackage(annotation)) {
|
||||
mergedAnnotations
|
||||
.add(findMergedAnnotation(root, annotation.annotationType()));
|
||||
}
|
||||
}
|
||||
}
|
||||
return mergedAnnotations;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
@ -79,7 +79,9 @@ class PropertyMappingContextCustomizer implements ContextCustomizer {
|
|||
Set<Class<?>> components = new LinkedHashSet<Class<?>>();
|
||||
Set<Class<?>> propertyMappings = new LinkedHashSet<Class<?>>();
|
||||
while (beanClass != null) {
|
||||
for (Annotation annotation : AnnotationUtils.getAnnotations(beanClass)) {
|
||||
Annotation[] annotations = AnnotationUtils.getAnnotations(beanClass);
|
||||
if (annotations != null) {
|
||||
for (Annotation annotation : annotations) {
|
||||
if (isAnnotated(annotation, Component.class)) {
|
||||
components.add(annotation.annotationType());
|
||||
}
|
||||
|
|
@ -87,6 +89,7 @@ class PropertyMappingContextCustomizer implements ContextCustomizer {
|
|||
propertyMappings.add(annotation.annotationType());
|
||||
}
|
||||
}
|
||||
}
|
||||
beanClass = beanClass.getSuperclass();
|
||||
}
|
||||
if (!components.isEmpty() && !propertyMappings.isEmpty()) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue