Browse Source

Polish nullability annotations

See gh-46926
pull/47162/head
Moritz Halbritter 3 months ago
parent
commit
0fc1a40f3b
  1. 2
      core/spring-boot-test/src/main/java/org/springframework/boot/test/util/TestPropertyValues.java
  2. 5
      module/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/jmx/EndpointMBean.java
  3. 3
      module/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/jmx/JacksonJmxOperationResponseMapper.java
  4. 4
      module/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/ServletEndpointRegistrar.java
  5. 5
      module/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/annotation/ControllerEndpointDiscoverer.java
  6. 5
      module/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/annotation/ServletEndpointDiscoverer.java
  7. 2
      module/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/HealthEndpoint.java
  8. 4
      module/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/ReactiveHealthEndpointWebExtension.java
  9. 6
      module/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/SystemHealthDescriptor.java

2
core/spring-boot-test/src/main/java/org/springframework/boot/test/util/TestPropertyValues.java

@ -186,7 +186,7 @@ public final class TestPropertyValues { @@ -186,7 +186,7 @@ public final class TestPropertyValues {
* @param call the call to make
* @return the result of the call
*/
public <T> T applyToSystemProperties(Callable<T> call) {
public <T extends @Nullable Object> T applyToSystemProperties(Callable<T> call) {
try (SystemPropertiesHandler handler = new SystemPropertiesHandler()) {
return call.call();
}

5
module/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/jmx/EndpointMBean.java

@ -55,7 +55,7 @@ public class EndpointMBean implements DynamicMBean { @@ -55,7 +55,7 @@ public class EndpointMBean implements DynamicMBean {
private final JmxOperationResponseMapper responseMapper;
private final ClassLoader classLoader;
private final @Nullable ClassLoader classLoader;
private final ExposableJmxEndpoint endpoint;
@ -63,7 +63,8 @@ public class EndpointMBean implements DynamicMBean { @@ -63,7 +63,8 @@ public class EndpointMBean implements DynamicMBean {
private final Map<String, JmxOperation> operations;
EndpointMBean(JmxOperationResponseMapper responseMapper, ClassLoader classLoader, ExposableJmxEndpoint endpoint) {
EndpointMBean(JmxOperationResponseMapper responseMapper, @Nullable ClassLoader classLoader,
ExposableJmxEndpoint endpoint) {
Assert.notNull(responseMapper, "'responseMapper' must not be null");
Assert.notNull(endpoint, "'endpoint' must not be null");
this.responseMapper = responseMapper;

3
module/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/jmx/JacksonJmxOperationResponseMapper.java

@ -24,6 +24,8 @@ import org.jspecify.annotations.Nullable; @@ -24,6 +24,8 @@ import org.jspecify.annotations.Nullable;
import tools.jackson.databind.JavaType;
import tools.jackson.databind.ObjectMapper;
import org.springframework.lang.Contract;
/**
* {@link JmxOperationResponseMapper} that delegates to a Jackson {@link ObjectMapper} to
* return a JSON response.
@ -58,6 +60,7 @@ public class JacksonJmxOperationResponseMapper implements JmxOperationResponseMa @@ -58,6 +60,7 @@ public class JacksonJmxOperationResponseMapper implements JmxOperationResponseMa
}
@Override
@Contract("!null -> !null")
public @Nullable Object mapResponse(@Nullable Object response) {
if (response == null) {
return null;

4
module/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/ServletEndpointRegistrar.java

@ -65,11 +65,11 @@ public class ServletEndpointRegistrar implements ServletContextInitializer { @@ -65,11 +65,11 @@ public class ServletEndpointRegistrar implements ServletContextInitializer {
private final EndpointAccessResolver endpointAccessResolver;
public ServletEndpointRegistrar(String basePath, Collection<ExposableServletEndpoint> servletEndpoints) {
public ServletEndpointRegistrar(@Nullable String basePath, Collection<ExposableServletEndpoint> servletEndpoints) {
this(basePath, servletEndpoints, (endpointId, defaultAccess) -> Access.NONE);
}
public ServletEndpointRegistrar(String basePath, Collection<ExposableServletEndpoint> servletEndpoints,
public ServletEndpointRegistrar(@Nullable String basePath, Collection<ExposableServletEndpoint> servletEndpoints,
EndpointAccessResolver endpointAccessResolver) {
Assert.notNull(servletEndpoints, "'servletEndpoints' must not be null");
this.basePath = cleanBasePath(basePath);

5
module/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/annotation/ControllerEndpointDiscoverer.java

@ -53,7 +53,7 @@ import org.springframework.core.annotation.MergedAnnotations.SearchStrategy; @@ -53,7 +53,7 @@ import org.springframework.core.annotation.MergedAnnotations.SearchStrategy;
public class ControllerEndpointDiscoverer extends EndpointDiscoverer<ExposableControllerEndpoint, Operation>
implements ControllerEndpointsSupplier {
private final List<PathMapper> endpointPathMappers;
private final @Nullable List<PathMapper> endpointPathMappers;
/**
* Create a new {@link ControllerEndpointDiscoverer} instance.
@ -61,7 +61,8 @@ public class ControllerEndpointDiscoverer extends EndpointDiscoverer<ExposableCo @@ -61,7 +61,8 @@ public class ControllerEndpointDiscoverer extends EndpointDiscoverer<ExposableCo
* @param endpointPathMappers the endpoint path mappers
* @param filters filters to apply
*/
public ControllerEndpointDiscoverer(ApplicationContext applicationContext, List<PathMapper> endpointPathMappers,
public ControllerEndpointDiscoverer(ApplicationContext applicationContext,
@Nullable List<PathMapper> endpointPathMappers,
Collection<EndpointFilter<ExposableControllerEndpoint>> filters) {
super(applicationContext, ParameterValueMapper.NONE, Collections.emptyList(), filters, Collections.emptyList());
this.endpointPathMappers = endpointPathMappers;

5
module/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/annotation/ServletEndpointDiscoverer.java

@ -53,7 +53,7 @@ import org.springframework.core.annotation.MergedAnnotations.SearchStrategy; @@ -53,7 +53,7 @@ import org.springframework.core.annotation.MergedAnnotations.SearchStrategy;
public class ServletEndpointDiscoverer extends EndpointDiscoverer<ExposableServletEndpoint, Operation>
implements ServletEndpointsSupplier {
private final List<PathMapper> endpointPathMappers;
private final @Nullable List<PathMapper> endpointPathMappers;
/**
* Create a new {@link ServletEndpointDiscoverer} instance.
@ -61,7 +61,8 @@ public class ServletEndpointDiscoverer extends EndpointDiscoverer<ExposableServl @@ -61,7 +61,8 @@ public class ServletEndpointDiscoverer extends EndpointDiscoverer<ExposableServl
* @param endpointPathMappers the endpoint path mappers
* @param filters filters to apply
*/
public ServletEndpointDiscoverer(ApplicationContext applicationContext, List<PathMapper> endpointPathMappers,
public ServletEndpointDiscoverer(ApplicationContext applicationContext,
@Nullable List<PathMapper> endpointPathMappers,
Collection<EndpointFilter<ExposableServletEndpoint>> filters) {
super(applicationContext, ParameterValueMapper.NONE, Collections.emptyList(), filters, Collections.emptyList());
this.endpointPathMappers = endpointPathMappers;

2
module/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/HealthEndpoint.java

@ -62,7 +62,7 @@ public class HealthEndpoint extends HealthEndpointSupport<Health, HealthDescript @@ -62,7 +62,7 @@ public class HealthEndpoint extends HealthEndpointSupport<Health, HealthDescript
*/
public HealthEndpoint(HealthContributorRegistry registry,
@Nullable ReactiveHealthContributorRegistry fallbackRegistry, HealthEndpointGroups groups,
Duration slowContributorLoggingThreshold) {
@Nullable Duration slowContributorLoggingThreshold) {
super(Contributor.blocking(registry, fallbackRegistry), groups, slowContributorLoggingThreshold);
}

4
module/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/ReactiveHealthEndpointWebExtension.java

@ -69,13 +69,13 @@ public class ReactiveHealthEndpointWebExtension @@ -69,13 +69,13 @@ public class ReactiveHealthEndpointWebExtension
@ReadOperation
public Mono<WebEndpointResponse<? extends HealthDescriptor>> health(ApiVersion apiVersion,
WebServerNamespace serverNamespace, SecurityContext securityContext) {
@Nullable WebServerNamespace serverNamespace, SecurityContext securityContext) {
return health(apiVersion, serverNamespace, securityContext, false, EMPTY_PATH);
}
@ReadOperation
public Mono<WebEndpointResponse<? extends HealthDescriptor>> health(ApiVersion apiVersion,
WebServerNamespace serverNamespace, SecurityContext securityContext,
@Nullable WebServerNamespace serverNamespace, SecurityContext securityContext,
@Selector(match = Match.ALL_REMAINING) String... path) {
return health(apiVersion, serverNamespace, securityContext, false, path);
}

6
module/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/SystemHealthDescriptor.java

@ -34,16 +34,16 @@ import org.springframework.boot.health.contributor.Status; @@ -34,16 +34,16 @@ import org.springframework.boot.health.contributor.Status;
*/
public final class SystemHealthDescriptor extends CompositeHealthDescriptor {
private final Set<String> groups;
private final @Nullable Set<String> groups;
SystemHealthDescriptor(ApiVersion apiVersion, Status status, @Nullable Map<String, HealthDescriptor> components,
Set<String> groups) {
@Nullable Set<String> groups) {
super(apiVersion, status, components);
this.groups = groups;
}
@JsonInclude(Include.NON_EMPTY)
public Set<String> getGroups() {
public @Nullable Set<String> getGroups() {
return this.groups;
}

Loading…
Cancel
Save