mirror of
https://github.com/spring-projects/spring-boot.git
synced 2026-09-17 12:09:16 +00:00
Improve null-safety of module/spring-boot-actuator-autoconfigure
See gh-46926
This commit is contained in:
+10
-1
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+4
-4
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
+2
@@ -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;
|
||||
|
||||
+10
-7
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user