Skip to content

Commit fcad7c4

Browse files
committed
Guard for null BeanFactory in @ConditionalOnBean
See gh-2080
1 parent d3ccdc6 commit fcad7c4

File tree

1 file changed

+3
-5
lines changed
  • spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition

1 file changed

+3
-5
lines changed

spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/OnBeanCondition.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,26 +111,24 @@ private List<String> getMatchingBeans(ConditionContext context, BeanSearchSpec b
111111
"Unable to use SearchStrategy.PARENTS");
112112
beanFactory = (ConfigurableListableBeanFactory) parent;
113113
}
114-
114+
if (beanFactory == null) {
115+
return Collections.emptyList();
116+
}
115117
List<String> beanNames = new ArrayList<String>();
116118
boolean considerHierarchy = beans.getStrategy() == SearchStrategy.ALL;
117-
118119
for (String type : beans.getTypes()) {
119120
beanNames.addAll(getBeanNamesForType(beanFactory, type,
120121
context.getClassLoader(), considerHierarchy));
121122
}
122-
123123
for (String annotation : beans.getAnnotations()) {
124124
beanNames.addAll(Arrays.asList(getBeanNamesForAnnotation(beanFactory,
125125
annotation, context.getClassLoader(), considerHierarchy)));
126126
}
127-
128127
for (String beanName : beans.getNames()) {
129128
if (containsBean(beanFactory, beanName, considerHierarchy)) {
130129
beanNames.add(beanName);
131130
}
132131
}
133-
134132
return beanNames;
135133
}
136134

0 commit comments

Comments
 (0)