Commit fcad7c4f authored by Phillip Webb's avatar Phillip Webb

Guard for null BeanFactory in @ConditionalOnBean

See gh-2080
parent d3ccdc63
...@@ -111,26 +111,24 @@ class OnBeanCondition extends SpringBootCondition implements ConfigurationCondit ...@@ -111,26 +111,24 @@ class OnBeanCondition extends SpringBootCondition implements ConfigurationCondit
"Unable to use SearchStrategy.PARENTS"); "Unable to use SearchStrategy.PARENTS");
beanFactory = (ConfigurableListableBeanFactory) parent; beanFactory = (ConfigurableListableBeanFactory) parent;
} }
if (beanFactory == null) {
return Collections.emptyList();
}
List<String> beanNames = new ArrayList<String>(); List<String> beanNames = new ArrayList<String>();
boolean considerHierarchy = beans.getStrategy() == SearchStrategy.ALL; boolean considerHierarchy = beans.getStrategy() == SearchStrategy.ALL;
for (String type : beans.getTypes()) { for (String type : beans.getTypes()) {
beanNames.addAll(getBeanNamesForType(beanFactory, type, beanNames.addAll(getBeanNamesForType(beanFactory, type,
context.getClassLoader(), considerHierarchy)); context.getClassLoader(), considerHierarchy));
} }
for (String annotation : beans.getAnnotations()) { for (String annotation : beans.getAnnotations()) {
beanNames.addAll(Arrays.asList(getBeanNamesForAnnotation(beanFactory, beanNames.addAll(Arrays.asList(getBeanNamesForAnnotation(beanFactory,
annotation, context.getClassLoader(), considerHierarchy))); annotation, context.getClassLoader(), considerHierarchy)));
} }
for (String beanName : beans.getNames()) { for (String beanName : beans.getNames()) {
if (containsBean(beanFactory, beanName, considerHierarchy)) { if (containsBean(beanFactory, beanName, considerHierarchy)) {
beanNames.add(beanName); beanNames.add(beanName);
} }
} }
return beanNames; return beanNames;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment