Refine null-safety in spring-webflux
See gh-32475
This commit is contained in:
@@ -22,6 +22,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.format.FormatterRegistry;
|
||||
import org.springframework.http.codec.ServerCodecConfigurer;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.validation.MessageCodesResolver;
|
||||
import org.springframework.validation.Validator;
|
||||
@@ -63,12 +64,14 @@ public class DelegatingWebFluxConfiguration extends WebFluxConfigurationSupport
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
protected Validator getValidator() {
|
||||
Validator validator = this.configurers.getValidator();
|
||||
return (validator != null ? validator : super.getValidator());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
protected MessageCodesResolver getMessageCodesResolver() {
|
||||
MessageCodesResolver messageCodesResolver = this.configurers.getMessageCodesResolver();
|
||||
return (messageCodesResolver != null ? messageCodesResolver : super.getMessageCodesResolver());
|
||||
@@ -110,6 +113,7 @@ public class DelegatingWebFluxConfiguration extends WebFluxConfigurationSupport
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
protected WebSocketService getWebSocketService() {
|
||||
WebSocketService service = this.configurers.getWebSocketService();
|
||||
return (service != null ? service : super.getWebSocketService());
|
||||
|
||||
@@ -61,11 +61,13 @@ public class WebFluxConfigurerComposite implements WebFluxConfigurer {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Validator getValidator() {
|
||||
return createSingleBean(WebFluxConfigurer::getValidator, Validator.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public MessageCodesResolver getMessageCodesResolver() {
|
||||
return createSingleBean(WebFluxConfigurer::getMessageCodesResolver, MessageCodesResolver.class);
|
||||
}
|
||||
|
||||
@@ -242,6 +242,7 @@ final class DefaultClientRequestBuilder implements ClientRequest.Builder {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Consumer<ClientHttpRequest> httpRequest() {
|
||||
return this.httpRequestConsumer;
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.springframework.web.reactive.function.client;
|
||||
|
||||
import org.springframework.core.NestedRuntimeException;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Abstract base class for exception published by {@link WebClient} in case of errors.
|
||||
@@ -42,7 +43,7 @@ public abstract class WebClientException extends NestedRuntimeException {
|
||||
* @param msg the message
|
||||
* @param ex the exception
|
||||
*/
|
||||
public WebClientException(String msg, Throwable ex) {
|
||||
public WebClientException(@Nullable String msg, Throwable ex) {
|
||||
super(msg, ex);
|
||||
}
|
||||
|
||||
|
||||
@@ -41,6 +41,7 @@ import org.springframework.http.codec.multipart.Part;
|
||||
import org.springframework.http.server.PathContainer;
|
||||
import org.springframework.http.server.RequestPath;
|
||||
import org.springframework.http.server.reactive.ServerHttpRequest;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
import org.springframework.web.bind.WebDataBinder;
|
||||
@@ -283,6 +284,7 @@ public class ServerRequestWrapper implements ServerRequest {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public InetSocketAddress host() {
|
||||
return this.headers.host();
|
||||
}
|
||||
|
||||
@@ -186,7 +186,7 @@ public abstract class AbstractUrlHandlerMapping extends AbstractHandlerMapping {
|
||||
* @param exchange current exchange
|
||||
*/
|
||||
@SuppressWarnings("UnusedParameters")
|
||||
protected void validateHandler(Object handler, ServerWebExchange exchange) {
|
||||
protected void validateHandler(@Nullable Object handler, ServerWebExchange exchange) {
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -22,6 +22,7 @@ import java.util.regex.Pattern;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
@@ -40,6 +41,7 @@ public abstract class AbstractFileNameVersionStrategy implements VersionStrategy
|
||||
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String extractVersion(String requestPath) {
|
||||
Matcher matcher = pattern.matcher(requestPath);
|
||||
if (matcher.find()) {
|
||||
|
||||
@@ -19,6 +19,7 @@ package org.springframework.web.reactive.resource;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
@@ -44,6 +45,7 @@ public abstract class AbstractPrefixVersionStrategy implements VersionStrategy {
|
||||
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String extractVersion(String requestPath) {
|
||||
return (requestPath.startsWith(this.prefix) ? this.prefix : null);
|
||||
}
|
||||
|
||||
@@ -400,6 +400,7 @@ public abstract class AbstractHandlerMethodMapping<T> extends AbstractHandlerMap
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
protected CorsConfiguration getCorsConfiguration(Object handler, ServerWebExchange exchange) {
|
||||
CorsConfiguration corsConfig = super.getCorsConfiguration(handler, exchange);
|
||||
if (handler instanceof HandlerMethod handlerMethod) {
|
||||
|
||||
@@ -36,6 +36,7 @@ import org.springframework.http.MediaType;
|
||||
import org.springframework.http.server.PathContainer;
|
||||
import org.springframework.http.server.reactive.ServerHttpRequest;
|
||||
import org.springframework.http.server.reactive.observation.ServerRequestObservationContext;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
@@ -87,6 +88,7 @@ public abstract class RequestMappingInfoHandlerMapping extends AbstractHandlerMe
|
||||
* @return an info in case of a match; or {@code null} otherwise.
|
||||
*/
|
||||
@Override
|
||||
@Nullable
|
||||
protected RequestMappingInfo getMatchingMapping(RequestMappingInfo info, ServerWebExchange exchange) {
|
||||
return info.getMatchingCondition(exchange);
|
||||
}
|
||||
@@ -171,6 +173,7 @@ public abstract class RequestMappingInfoHandlerMapping extends AbstractHandlerMe
|
||||
* method but not by query parameter conditions
|
||||
*/
|
||||
@Override
|
||||
@Nullable
|
||||
protected HandlerMethod handleNoMatch(Set<RequestMappingInfo> infos,
|
||||
ServerWebExchange exchange) throws Exception {
|
||||
|
||||
|
||||
@@ -65,6 +65,7 @@ public class CookieValueMethodArgumentResolver extends AbstractNamedValueSyncArg
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
protected Object resolveNamedValue(String name, MethodParameter parameter, ServerWebExchange exchange) {
|
||||
HttpCookie cookie = exchange.getRequest().getCookies().getFirst(name);
|
||||
Class<?> paramType = parameter.getNestedParameterType();
|
||||
|
||||
@@ -63,6 +63,7 @@ public class ExpressionValueMethodArgumentResolver extends AbstractNamedValueSyn
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
protected Object resolveNamedValue(String name, MethodParameter parameter, ServerWebExchange exchange) {
|
||||
// No name to resolve
|
||||
return null;
|
||||
|
||||
@@ -85,6 +85,7 @@ public class PathVariableMethodArgumentResolver extends AbstractNamedValueSyncAr
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
protected Object resolveNamedValue(String name, MethodParameter parameter, ServerWebExchange exchange) {
|
||||
String attributeName = HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE;
|
||||
return exchange.getAttributeOrDefault(attributeName, Collections.emptyMap()).get(name);
|
||||
|
||||
@@ -78,6 +78,7 @@ public class RequestHeaderMethodArgumentResolver extends AbstractNamedValueSyncA
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
protected Object resolveNamedValue(String name, MethodParameter parameter, ServerWebExchange exchange) {
|
||||
List<String> headerValues = exchange.getRequest().getHeaders().get(name);
|
||||
Object result = null;
|
||||
|
||||
@@ -356,6 +356,7 @@ public class RequestMappingHandlerMapping extends RequestMappingInfoHandlerMappi
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
protected CorsConfiguration initCorsConfiguration(Object handler, Method method, RequestMappingInfo mappingInfo) {
|
||||
HandlerMethod handlerMethod = createHandlerMethod(handler, method);
|
||||
Class<?> beanType = handlerMethod.getBeanType();
|
||||
|
||||
@@ -98,6 +98,7 @@ public class RequestParamMethodArgumentResolver extends AbstractNamedValueSyncAr
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
protected Object resolveNamedValue(String name, MethodParameter parameter, ServerWebExchange exchange) {
|
||||
List<String> paramValues = exchange.getRequest().getQueryParams().get(name);
|
||||
Object result = null;
|
||||
|
||||
Reference in New Issue
Block a user