Skip to content

Commit a1fe05f

Browse files
qxowilkinsona
authored andcommitted
Fix NPE in configprops endpoint
This works around spring-projects/spring-framework#28298. The bug means that when a @configuration class is annotated with @ConfigurationProperties any bean defined by a static @bean method is considered to be annotated with @ConfigurationProperties. See gh-30068
1 parent e3859fa commit a1fe05f

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/context/properties/ConfigurationPropertiesReportEndpoint.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public void keysToSanitize(String... keysToSanitize) {
121121

122122
@ReadOperation
123123
public ApplicationConfigurationProperties configurationProperties() {
124-
return extract(this.context, (bean) -> true);
124+
return extract(this.context, (bean) -> bean != null);
125125
}
126126

127127
@ReadOperation

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
@@ -144,7 +144,13 @@ public static Map<String, ConfigurationPropertiesBean> getAll(ApplicationContext
144144
}
145145
Map<String, ConfigurationPropertiesBean> propertiesBeans = new LinkedHashMap<>();
146146
applicationContext.getBeansWithAnnotation(ConfigurationProperties.class)
147-
.forEach((beanName, bean) -> propertiesBeans.put(beanName, get(applicationContext, bean, beanName)));
147+
.forEach((beanName, bean) -> {
148+
ConfigurationPropertiesBean propertiesBean = get(applicationContext, bean, beanName);
149+
if (propertiesBean == null) { //ignore for null
150+
return;
151+
}
152+
propertiesBeans.put(beanName,propertiesBean);
153+
});
148154
return propertiesBeans;
149155
}
150156

@@ -158,6 +164,9 @@ private static Map<String, ConfigurationPropertiesBean> getAll(ConfigurableAppli
158164
try {
159165
Object bean = beanFactory.getBean(beanName);
160166
ConfigurationPropertiesBean propertiesBean = get(applicationContext, bean, beanName);
167+
if (propertiesBean == null) { //ignore for null
168+
continue;
169+
}
161170
propertiesBeans.put(beanName, propertiesBean);
162171
}
163172
catch (Exception ex) {

0 commit comments

Comments
 (0)