Skip to content

Commit d87b625

Browse files
committed
fix: ConfigurationPropertiesBean.getAll should ignored the null value (ConfigurationPropertiesBean) in the return Map.
ref: https://github.com/qxo/springboot-actuator-configprops-npe-poc
1 parent bff9e79 commit d87b625

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationPropertiesBean.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,13 @@ public static Map<String, ConfigurationPropertiesBean> getAll(ApplicationContext
149149
}
150150
Map<String, ConfigurationPropertiesBean> propertiesBeans = new LinkedHashMap<>();
151151
applicationContext.getBeansWithAnnotation(ConfigurationProperties.class)
152-
.forEach((beanName, bean) -> propertiesBeans.put(beanName, get(applicationContext, bean, beanName)));
152+
.forEach((beanName, bean) -> {
153+
ConfigurationPropertiesBean propertiesBean = get(applicationContext, bean, beanName);
154+
if (propertiesBean == null) { //ignore for null
155+
return;
156+
}
157+
propertiesBeans.put(beanName,propertiesBean);
158+
});
153159
return propertiesBeans;
154160
}
155161

@@ -163,6 +169,9 @@ private static Map<String, ConfigurationPropertiesBean> getAll(ConfigurableAppli
163169
try {
164170
Object bean = beanFactory.getBean(beanName);
165171
ConfigurationPropertiesBean propertiesBean = get(applicationContext, bean, beanName);
172+
if (propertiesBean == null) { //ignore for null
173+
continue;
174+
}
166175
propertiesBeans.put(beanName, propertiesBean);
167176
}
168177
catch (Exception ex) {

0 commit comments

Comments
 (0)