Improve null-safety of module/spring-boot-actuator-autoconfigure

See gh-46926
This commit is contained in:
Moritz Halbritter
2025-08-26 14:22:54 +02:00
parent 3a40b0a623
commit 2e09df4e1a
4 changed files with 26 additions and 12 deletions
@@ -122,7 +122,11 @@ class AvailabilityProbesHealthEndpointGroups implements HealthEndpointGroups, Ad
}
List<String> additionalPaths = new ArrayList<>();
if (this.groups instanceof AdditionalPathsMapper additionalPathsMapper) {
additionalPaths.addAll(additionalPathsMapper.getAdditionalPaths(endpointId, webServerNamespace));
List<String> mappedAdditionalPaths = getAdditionalPaths(endpointId, webServerNamespace,
additionalPathsMapper);
if (mappedAdditionalPaths != null) {
additionalPaths.addAll(mappedAdditionalPaths);
}
}
additionalPaths.addAll(this.probeGroups.values()
.stream()
@@ -134,4 +138,9 @@ class AvailabilityProbesHealthEndpointGroups implements HealthEndpointGroups, Ad
return additionalPaths;
}
private static @Nullable List<String> getAdditionalPaths(EndpointId endpointId,
WebServerNamespace webServerNamespace, AdditionalPathsMapper additionalPathsMapper) {
return additionalPathsMapper.getAdditionalPaths(endpointId, webServerNamespace);
}
}
@@ -63,7 +63,7 @@ public class ConditionsReportEndpoint {
@ReadOperation
public ConditionsDescriptor conditions() {
Map<String, ContextConditionsDescriptor> contextConditionEvaluations = new HashMap<>();
Map<@Nullable String, ContextConditionsDescriptor> contextConditionEvaluations = new HashMap<>();
ConfigurableApplicationContext target = this.context;
while (target != null) {
contextConditionEvaluations.put(target.getId(), new ContextConditionsDescriptor(target));
@@ -85,13 +85,13 @@ public class ConditionsReportEndpoint {
*/
public static final class ConditionsDescriptor implements OperationResponseBody {
private final Map<String, ContextConditionsDescriptor> contexts;
private final Map<@Nullable String, ContextConditionsDescriptor> contexts;
private ConditionsDescriptor(Map<String, ContextConditionsDescriptor> contexts) {
private ConditionsDescriptor(Map<@Nullable String, ContextConditionsDescriptor> contexts) {
this.contexts = contexts;
}
public Map<String, ContextConditionsDescriptor> getContexts() {
public Map<@Nullable String, ContextConditionsDescriptor> getContexts() {
return this.contexts;
}
@@ -21,6 +21,7 @@ import org.jspecify.annotations.Nullable;
import org.springframework.boot.web.server.WebServerFactory;
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.core.Ordered;
import org.springframework.lang.Contract;
/**
* Base class for a {@link WebServerFactoryCustomizer} that customizes the web server's
@@ -39,6 +40,7 @@ public abstract class AccessLogCustomizer<T extends WebServerFactory>
this.prefix = prefix;
}
@Contract("!null -> !null")
protected @Nullable String customizePrefix(@Nullable String existingPrefix) {
if (this.prefix == null) {
return existingPrefix;
@@ -85,32 +85,35 @@ class ChildManagementContextInitializer implements BeanRegistrationAotProcessor,
if (!(this.parentContext instanceof WebServerApplicationContext)) {
return;
}
if (this.managementContext == null) {
ConfigurableApplicationContext managementContext = createManagementContext();
ConfigurableApplicationContext managementContext = this.managementContext;
if (managementContext == null) {
managementContext = createManagementContext();
registerBeans(managementContext);
managementContext.refresh();
this.managementContext = managementContext;
}
else {
this.managementContext.start();
managementContext.start();
}
}
@Override
public void stop() {
if (this.managementContext != null) {
ConfigurableApplicationContext managementContext = this.managementContext;
if (managementContext != null) {
if (this.parentContext.isClosed()) {
this.managementContext.close();
managementContext.close();
}
else {
this.managementContext.stop();
managementContext.stop();
}
}
}
@Override
public boolean isRunning() {
return this.managementContext != null && this.managementContext.isRunning();
ConfigurableApplicationContext managementContext = this.managementContext;
return managementContext != null && managementContext.isRunning();
}
@Override