Merge branch '6.1.x'

This commit is contained in:
Sébastien Deleuze 2024-03-25 11:04:49 +01:00
commit 2b1eb488fc
59 changed files with 106 additions and 23 deletions

View File

@ -211,6 +211,7 @@ final class DefaultErrorResponseBuilder implements ErrorResponse.Builder {
} }
@Override @Override
@Nullable
public Object[] getDetailMessageArguments() { public Object[] getDetailMessageArguments() {
return this.detailMessageArguments; return this.detailMessageArguments;
} }

View File

@ -165,6 +165,7 @@ public class ErrorResponseException extends NestedRuntimeException implements Er
} }
@Override @Override
@Nullable
public Object[] getDetailMessageArguments() { public Object[] getDetailMessageArguments() {
return this.messageDetailArguments; return this.messageDetailArguments;
} }

View File

@ -73,7 +73,7 @@ public abstract class HttpMediaTypeException extends ServletException implements
* resolving the problem "detail" through a {@code MessageSource} * resolving the problem "detail" through a {@code MessageSource}
* @since 6.0 * @since 6.0
*/ */
protected HttpMediaTypeException(String message, List<MediaType> supportedMediaTypes, protected HttpMediaTypeException(@Nullable String message, List<MediaType> supportedMediaTypes,
@Nullable String messageDetailCode, @Nullable Object[] messageDetailArguments) { @Nullable String messageDetailCode, @Nullable Object[] messageDetailArguments) {
super(message); super(message);
@ -102,6 +102,7 @@ public abstract class HttpMediaTypeException extends ServletException implements
} }
@Override @Override
@Nullable
public Object[] getDetailMessageArguments() { public Object[] getDetailMessageArguments() {
return this.messageDetailArguments; return this.messageDetailArguments;
} }

View File

@ -63,7 +63,7 @@ public class HttpMediaTypeNotSupportedException extends HttpMediaTypeException {
* @param mediaTypes list of supported media types * @param mediaTypes list of supported media types
* @since 6.0.5 * @since 6.0.5
*/ */
public HttpMediaTypeNotSupportedException(String message, List<MediaType> mediaTypes) { public HttpMediaTypeNotSupportedException(@Nullable String message, List<MediaType> mediaTypes) {
super(message, mediaTypes, PARSE_ERROR_DETAIL_CODE, null); super(message, mediaTypes, PARSE_ERROR_DETAIL_CODE, null);
this.contentType = null; this.contentType = null;
this.httpMethod = null; this.httpMethod = null;

View File

@ -99,6 +99,7 @@ public class ServletPathExtensionContentNegotiationStrategy extends PathExtensio
* @since 4.3 * @since 4.3
*/ */
@Override @Override
@Nullable
public MediaType getMediaTypeForResource(Resource resource) { public MediaType getMediaTypeForResource(Resource resource) {
MediaType mediaType = null; MediaType mediaType = null;
String mimeType = this.servletContext.getMimeType(resource.getFilename()); String mimeType = this.servletContext.getMimeType(resource.getFilename());

View File

@ -50,7 +50,7 @@ public class ServletRequestBindingException extends ServletException implements
* Constructor with a message only. * Constructor with a message only.
* @param msg the detail message * @param msg the detail message
*/ */
public ServletRequestBindingException(String msg) { public ServletRequestBindingException(@Nullable String msg) {
this(msg, null, null); this(msg, null, null);
} }
@ -59,7 +59,7 @@ public class ServletRequestBindingException extends ServletException implements
* @param msg the detail message * @param msg the detail message
* @param cause the root cause * @param cause the root cause
*/ */
public ServletRequestBindingException(String msg, Throwable cause) { public ServletRequestBindingException(@Nullable String msg, @Nullable Throwable cause) {
this(msg, cause, null, null); this(msg, cause, null, null);
} }
@ -73,7 +73,7 @@ public class ServletRequestBindingException extends ServletException implements
* @since 6.0 * @since 6.0
*/ */
protected ServletRequestBindingException( protected ServletRequestBindingException(
String msg, @Nullable String messageDetailCode, @Nullable Object[] messageDetailArguments) { @Nullable String msg, @Nullable String messageDetailCode, @Nullable Object[] messageDetailArguments) {
this(msg, null, messageDetailCode, messageDetailArguments); this(msg, null, messageDetailCode, messageDetailArguments);
} }
@ -88,7 +88,7 @@ public class ServletRequestBindingException extends ServletException implements
* resolving the problem "detail" through a {@code MessageSource} * resolving the problem "detail" through a {@code MessageSource}
* @since 6.0 * @since 6.0
*/ */
protected ServletRequestBindingException(String msg, @Nullable Throwable cause, protected ServletRequestBindingException(@Nullable String msg, @Nullable Throwable cause,
@Nullable String messageDetailCode, @Nullable Object[] messageDetailArguments) { @Nullable String messageDetailCode, @Nullable Object[] messageDetailArguments) {
super(msg, cause); super(msg, cause);
@ -118,6 +118,7 @@ public class ServletRequestBindingException extends ServletException implements
} }
@Override @Override
@Nullable
public Object[] getDetailMessageArguments() { public Object[] getDetailMessageArguments() {
return this.messageDetailArguments; return this.messageDetailArguments;
} }

View File

@ -17,6 +17,7 @@
package org.springframework.web.bind.support; package org.springframework.web.bind.support;
import org.springframework.core.MethodParameter; import org.springframework.core.MethodParameter;
import org.springframework.lang.Nullable;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import org.springframework.validation.DataBinder; import org.springframework.validation.DataBinder;
import org.springframework.web.bind.annotation.BindParam; import org.springframework.web.bind.annotation.BindParam;
@ -32,6 +33,7 @@ import org.springframework.web.bind.annotation.BindParam;
public final class BindParamNameResolver implements DataBinder.NameResolver { public final class BindParamNameResolver implements DataBinder.NameResolver {
@Override @Override
@Nullable
public String resolveName(MethodParameter parameter) { public String resolveName(MethodParameter parameter) {
BindParam bindParam = parameter.getParameterAnnotation(BindParam.class); BindParam bindParam = parameter.getParameterAnnotation(BindParam.class);
if (bindParam != null) { if (bindParam != null) {

View File

@ -162,6 +162,7 @@ public class WebExchangeDataBinder extends WebDataBinder {
private record MapValueResolver(Map<String, Object> map) implements ValueResolver { private record MapValueResolver(Map<String, Object> map) implements ValueResolver {
@Override @Override
@Nullable
public Object resolveValue(String name, Class<?> type) { public Object resolveValue(String name, Class<?> type) {
return this.map.get(name); return this.map.get(name);
} }

View File

@ -84,6 +84,7 @@ public class HttpMessageConverterExtractor<T> implements ResponseExtractor<T> {
@Override @Override
@Nullable
@SuppressWarnings({"rawtypes", "unchecked", "resource"}) @SuppressWarnings({"rawtypes", "unchecked", "resource"})
public T extractData(ClientHttpResponse response) throws IOException { public T extractData(ClientHttpResponse response) throws IOException {
IntrospectingClientHttpResponse responseWrapper = new IntrospectingClientHttpResponse(response); IntrospectingClientHttpResponse responseWrapper = new IntrospectingClientHttpResponse(response);

View File

@ -18,6 +18,8 @@ package org.springframework.web.client;
import java.io.IOException; import java.io.IOException;
import org.springframework.lang.Nullable;
/** /**
* Exception thrown when an I/O error occurs. * Exception thrown when an I/O error occurs.
* *
@ -42,7 +44,7 @@ public class ResourceAccessException extends RestClientException {
* @param msg the message * @param msg the message
* @param ex the {@code IOException} * @param ex the {@code IOException}
*/ */
public ResourceAccessException(String msg, IOException ex) { public ResourceAccessException(String msg, @Nullable IOException ex) {
super(msg, ex); super(msg, ex);
} }

View File

@ -18,6 +18,7 @@ package org.springframework.web.client;
import org.springframework.core.NestedRuntimeException; import org.springframework.core.NestedRuntimeException;
import org.springframework.http.client.ClientHttpResponse; import org.springframework.http.client.ClientHttpResponse;
import org.springframework.lang.Nullable;
/** /**
* Base class for exceptions thrown by {@link RestTemplate} in case a request * Base class for exceptions thrown by {@link RestTemplate} in case a request
@ -47,7 +48,7 @@ public class RestClientException extends NestedRuntimeException {
* @param msg the message * @param msg the message
* @param ex the exception * @param ex the exception
*/ */
public RestClientException(String msg, Throwable ex) { public RestClientException(String msg, @Nullable Throwable ex) {
super(msg, ex); super(msg, ex);
} }

View File

@ -25,6 +25,7 @@ import org.springframework.http.HttpCookie;
import org.springframework.http.HttpHeaders; import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod; import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.web.client.RestClient; import org.springframework.web.client.RestClient;
import org.springframework.web.service.invoker.HttpExchangeAdapter; import org.springframework.web.service.invoker.HttpExchangeAdapter;
@ -69,6 +70,7 @@ public final class RestClientAdapter implements HttpExchangeAdapter {
} }
@Override @Override
@Nullable
public <T> T exchangeForBody(HttpRequestValues values, ParameterizedTypeReference<T> bodyType) { public <T> T exchangeForBody(HttpRequestValues values, ParameterizedTypeReference<T> bodyType) {
return newRequest(values).retrieve().body(bodyType); return newRequest(values).retrieve().body(bodyType);
} }

View File

@ -24,6 +24,7 @@ import jakarta.faces.context.FacesContext;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.util.ReflectionUtils; import org.springframework.util.ReflectionUtils;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
@ -102,6 +103,7 @@ public class FacesRequestAttributes implements RequestAttributes {
@Override @Override
@Nullable
public Object getAttribute(String name, int scope) { public Object getAttribute(String name, int scope) {
return getAttributeMap(scope).get(name); return getAttributeMap(scope).get(name);
} }
@ -130,6 +132,7 @@ public class FacesRequestAttributes implements RequestAttributes {
} }
@Override @Override
@Nullable
public Object resolveReference(String key) { public Object resolveReference(String key) {
return switch (key) { return switch (key) {
case REFERENCE_REQUEST -> getExternalContext().getRequest(); case REFERENCE_REQUEST -> getExternalContext().getRequest();

View File

@ -58,6 +58,7 @@ public class FacesWebRequest extends FacesRequestAttributes implements NativeWeb
} }
@Override @Override
@Nullable
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public <T> T getNativeRequest(@Nullable Class<T> requiredType) { public <T> T getNativeRequest(@Nullable Class<T> requiredType) {
if (requiredType != null) { if (requiredType != null) {
@ -70,6 +71,7 @@ public class FacesWebRequest extends FacesRequestAttributes implements NativeWeb
} }
@Override @Override
@Nullable
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public <T> T getNativeResponse(@Nullable Class<T> requiredType) { public <T> T getNativeResponse(@Nullable Class<T> requiredType) {
if (requiredType != null) { if (requiredType != null) {

View File

@ -143,6 +143,7 @@ public class ServletRequestAttributes extends AbstractRequestAttributes {
@Override @Override
@Nullable
public Object getAttribute(String name, int scope) { public Object getAttribute(String name, int scope) {
if (scope == SCOPE_REQUEST) { if (scope == SCOPE_REQUEST) {
if (!isRequestActive()) { if (!isRequestActive()) {
@ -242,6 +243,7 @@ public class ServletRequestAttributes extends AbstractRequestAttributes {
} }
@Override @Override
@Nullable
public Object resolveReference(String key) { public Object resolveReference(String key) {
if (REFERENCE_REQUEST.equals(key)) { if (REFERENCE_REQUEST.equals(key)) {
return this.request; return this.request;

View File

@ -98,16 +98,19 @@ public class ServletWebRequest extends ServletRequestAttributes implements Nativ
} }
@Override @Override
@Nullable
public Object getNativeResponse() { public Object getNativeResponse() {
return getResponse(); return getResponse();
} }
@Override @Override
@Nullable
public <T> T getNativeRequest(@Nullable Class<T> requiredType) { public <T> T getNativeRequest(@Nullable Class<T> requiredType) {
return WebUtils.getNativeRequest(getRequest(), requiredType); return WebUtils.getNativeRequest(getRequest(), requiredType);
} }
@Override @Override
@Nullable
public <T> T getNativeResponse(@Nullable Class<T> requiredType) { public <T> T getNativeResponse(@Nullable Class<T> requiredType) {
HttpServletResponse response = getResponse(); HttpServletResponse response = getResponse();
return (response != null ? WebUtils.getNativeResponse(response, requiredType) : null); return (response != null ? WebUtils.getNativeResponse(response, requiredType) : null);

View File

@ -101,7 +101,7 @@ public class StandardServletAsyncWebRequest extends ServletWebRequest implements
* container processing thread has exited. * container processing thread has exited.
*/ */
@Override @Override
public void setTimeout(Long timeout) { public void setTimeout(@Nullable Long timeout) {
Assert.state(!isAsyncStarted(), "Cannot change the timeout with concurrent handling in progress"); Assert.state(!isAsyncStarted(), "Cannot change the timeout with concurrent handling in progress");
this.timeout = timeout; this.timeout = timeout;
} }

View File

@ -77,6 +77,7 @@ public class ServletContextAttributeFactoryBean implements FactoryBean<Object>,
} }
@Override @Override
@Nullable
public Class<?> getObjectType() { public Class<?> getObjectType() {
return (this.attribute != null ? this.attribute.getClass() : null); return (this.attribute != null ? this.attribute.getClass() : null);
} }

View File

@ -139,6 +139,7 @@ public class StaticWebApplicationContext extends StaticApplicationContext
} }
@Override @Override
@Nullable
public String[] getConfigLocations() { public String[] getConfigLocations() {
return null; return null;
} }

View File

@ -155,7 +155,7 @@ public class DefaultCorsProcessor implements CorsProcessor {
responseHeaders.setAccessControlAllowMethods(allowMethods); responseHeaders.setAccessControlAllowMethods(allowMethods);
} }
if (preFlightRequest && !allowHeaders.isEmpty()) { if (preFlightRequest && !CollectionUtils.isEmpty(allowHeaders)) {
responseHeaders.setAccessControlAllowHeaders(allowHeaders); responseHeaders.setAccessControlAllowHeaders(allowHeaders);
} }

View File

@ -153,7 +153,7 @@ public class DefaultCorsProcessor implements CorsProcessor {
responseHeaders.setAccessControlAllowMethods(allowMethods); responseHeaders.setAccessControlAllowMethods(allowMethods);
} }
if (preFlightRequest && !allowHeaders.isEmpty()) { if (preFlightRequest && !CollectionUtils.isEmpty(allowHeaders)) {
responseHeaders.setAccessControlAllowHeaders(allowHeaders); responseHeaders.setAccessControlAllowHeaders(allowHeaders);
} }

View File

@ -340,6 +340,7 @@ public class ForwardedHeaderFilter extends OncePerRequestFilter {
@SuppressWarnings("DataFlowIssue") @SuppressWarnings("DataFlowIssue")
@Override @Override
@Nullable
public Object getAttribute(String name) { public Object getAttribute(String name) {
if (name.equals(WebUtils.ERROR_REQUEST_URI_ATTRIBUTE)) { if (name.equals(WebUtils.ERROR_REQUEST_URI_ATTRIBUTE)) {
return this.forwardedPrefixExtractor.getErrorRequestUri(); return this.forwardedPrefixExtractor.getErrorRequestUri();

View File

@ -139,6 +139,7 @@ public class ServerHttpObservationFilter extends OncePerRequestFilter {
return observation; return observation;
} }
@Nullable
private Throwable unwrapServletException(Throwable ex) { private Throwable unwrapServletException(Throwable ex) {
return (ex instanceof ServletException) ? ex.getCause() : ex; return (ex instanceof ServletException) ? ex.getCause() : ex;
} }

View File

@ -174,6 +174,7 @@ public class ExceptionHandlerMethodResolver {
* Return the {@link Method} mapped to the given exception type, or * Return the {@link Method} mapped to the given exception type, or
* {@link #NO_MATCHING_EXCEPTION_HANDLER_METHOD} if none. * {@link #NO_MATCHING_EXCEPTION_HANDLER_METHOD} if none.
*/ */
@Nullable
private Method getMappedMethod(Class<? extends Throwable> exceptionType) { private Method getMappedMethod(Class<? extends Throwable> exceptionType) {
List<Class<? extends Throwable>> matches = new ArrayList<>(); List<Class<? extends Throwable>> matches = new ArrayList<>();
for (Class<? extends Throwable> mappedException : this.mappedMethods.keySet()) { for (Class<? extends Throwable> mappedException : this.mappedMethods.keySet()) {

View File

@ -37,7 +37,7 @@ public class MethodArgumentConversionNotSupportedException extends ConversionNot
public MethodArgumentConversionNotSupportedException(@Nullable Object value, public MethodArgumentConversionNotSupportedException(@Nullable Object value,
@Nullable Class<?> requiredType, String name, MethodParameter param, Throwable cause) { @Nullable Class<?> requiredType, String name, MethodParameter param, @Nullable Throwable cause) {
super(value, requiredType, cause); super(value, requiredType, cause);
this.name = name; this.name = name;

View File

@ -37,7 +37,7 @@ public class MethodArgumentTypeMismatchException extends TypeMismatchException {
public MethodArgumentTypeMismatchException(@Nullable Object value, public MethodArgumentTypeMismatchException(@Nullable Object value,
@Nullable Class<?> requiredType, String name, MethodParameter param, Throwable cause) { @Nullable Class<?> requiredType, String name, MethodParameter param, @Nullable Throwable cause) {
super(value, requiredType, cause); super(value, requiredType, cause);
this.name = name; this.name = name;

View File

@ -65,6 +65,7 @@ class MultipartFileResource extends AbstractResource {
} }
@Override @Override
@Nullable
public String getFilename() { public String getFilename() {
return this.multipartFile.getOriginalFilename(); return this.multipartFile.getOriginalFilename();
} }

View File

@ -130,6 +130,7 @@ public class DefaultMultipartHttpServletRequest extends AbstractMultipartHttpSer
} }
@Override @Override
@Nullable
public String getMultipartContentType(String paramOrFileName) { public String getMultipartContentType(String paramOrFileName) {
MultipartFile file = getFile(paramOrFileName); MultipartFile file = getFile(paramOrFileName);
if (file != null) { if (file != null) {
@ -141,6 +142,7 @@ public class DefaultMultipartHttpServletRequest extends AbstractMultipartHttpSer
} }
@Override @Override
@Nullable
public HttpHeaders getMultipartHeaders(String paramOrFileName) { public HttpHeaders getMultipartHeaders(String paramOrFileName) {
String contentType = getMultipartContentType(paramOrFileName); String contentType = getMultipartContentType(paramOrFileName);
if (contentType != null) { if (contentType != null) {
@ -167,6 +169,7 @@ public class DefaultMultipartHttpServletRequest extends AbstractMultipartHttpSer
* lazily initializing it if necessary. * lazily initializing it if necessary.
* @see #initializeMultipart() * @see #initializeMultipart()
*/ */
@SuppressWarnings("NullAway")
protected Map<String, String[]> getMultipartParameters() { protected Map<String, String[]> getMultipartParameters() {
if (this.multipartParameters == null) { if (this.multipartParameters == null) {
initializeMultipart(); initializeMultipart();
@ -187,6 +190,7 @@ public class DefaultMultipartHttpServletRequest extends AbstractMultipartHttpSer
* lazily initializing it if necessary. * lazily initializing it if necessary.
* @see #initializeMultipart() * @see #initializeMultipart()
*/ */
@SuppressWarnings("NullAway")
protected Map<String, String> getMultipartParameterContentTypes() { protected Map<String, String> getMultipartParameterContentTypes() {
if (this.multipartParameterContentTypes == null) { if (this.multipartParameterContentTypes == null) {
initializeMultipart(); initializeMultipart();

View File

@ -177,6 +177,7 @@ public class StandardMultipartHttpServletRequest extends AbstractMultipartHttpSe
} }
@Override @Override
@Nullable
public String getMultipartContentType(String paramOrFileName) { public String getMultipartContentType(String paramOrFileName) {
try { try {
Part part = getPart(paramOrFileName); Part part = getPart(paramOrFileName);
@ -188,6 +189,7 @@ public class StandardMultipartHttpServletRequest extends AbstractMultipartHttpSe
} }
@Override @Override
@Nullable
public HttpHeaders getMultipartHeaders(String paramOrFileName) { public HttpHeaders getMultipartHeaders(String paramOrFileName) {
try { try {
Part part = getPart(paramOrFileName); Part part = getPart(paramOrFileName);

View File

@ -94,6 +94,7 @@ public class ServerWebExchangeDecorator implements ServerWebExchange {
} }
@Override @Override
@Nullable
public ApplicationContext getApplicationContext() { public ApplicationContext getApplicationContext() {
return getDelegate().getApplicationContext(); return getDelegate().getApplicationContext();
} }

View File

@ -18,6 +18,7 @@ package org.springframework.web.service.invoker;
import org.springframework.core.MethodParameter; import org.springframework.core.MethodParameter;
import org.springframework.core.convert.ConversionService; import org.springframework.core.convert.ConversionService;
import org.springframework.lang.Nullable;
import org.springframework.web.bind.annotation.CookieValue; import org.springframework.web.bind.annotation.CookieValue;
/** /**
@ -56,6 +57,7 @@ public class CookieValueArgumentResolver extends AbstractNamedValueArgumentResol
@Override @Override
@Nullable
protected NamedValueInfo createNamedValueInfo(MethodParameter parameter) { protected NamedValueInfo createNamedValueInfo(MethodParameter parameter) {
CookieValue annot = parameter.getParameterAnnotation(CookieValue.class); CookieValue annot = parameter.getParameterAnnotation(CookieValue.class);
return (annot == null ? null : return (annot == null ? null :

View File

@ -408,7 +408,7 @@ public class HttpRequestValues {
/** /**
* Set the request body as an Object to be serialized. * Set the request body as an Object to be serialized.
*/ */
public void setBodyValue(Object bodyValue) { public void setBodyValue(@Nullable Object bodyValue) {
this.bodyValue = bodyValue; this.bodyValue = bodyValue;
} }

View File

@ -294,6 +294,7 @@ public final class HttpServiceProxyFactory {
} }
@Override @Override
@Nullable
public Object invoke(MethodInvocation invocation) throws Throwable { public Object invoke(MethodInvocation invocation) throws Throwable {
Method method = invocation.getMethod(); Method method = invocation.getMethod();
HttpServiceMethod httpServiceMethod = this.httpServiceMethods.get(method); HttpServiceMethod httpServiceMethod = this.httpServiceMethods.get(method);

View File

@ -18,6 +18,7 @@ package org.springframework.web.service.invoker;
import org.springframework.core.MethodParameter; import org.springframework.core.MethodParameter;
import org.springframework.core.convert.ConversionService; import org.springframework.core.convert.ConversionService;
import org.springframework.lang.Nullable;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
/** /**
@ -48,6 +49,7 @@ public class PathVariableArgumentResolver extends AbstractNamedValueArgumentReso
@Override @Override
@Nullable
protected NamedValueInfo createNamedValueInfo(MethodParameter parameter) { protected NamedValueInfo createNamedValueInfo(MethodParameter parameter) {
PathVariable annot = parameter.getParameterAnnotation(PathVariable.class); PathVariable annot = parameter.getParameterAnnotation(PathVariable.class);
return (annot == null ? null : return (annot == null ? null :

View File

@ -224,7 +224,7 @@ public final class ReactiveHttpRequestValues extends HttpRequestValues {
* body publisher}. * body publisher}.
*/ */
@Override @Override
public void setBodyValue(Object bodyValue) { public void setBodyValue(@Nullable Object bodyValue) {
super.setBodyValue(bodyValue); super.setBodyValue(bodyValue);
this.body = null; this.body = null;
this.bodyElementType = null; this.bodyElementType = null;

View File

@ -17,6 +17,7 @@
package org.springframework.web.service.invoker; package org.springframework.web.service.invoker;
import org.springframework.core.MethodParameter; import org.springframework.core.MethodParameter;
import org.springframework.lang.Nullable;
import org.springframework.web.bind.annotation.RequestAttribute; import org.springframework.web.bind.annotation.RequestAttribute;
/** /**
@ -40,6 +41,7 @@ public class RequestAttributeArgumentResolver extends AbstractNamedValueArgument
@Override @Override
@Nullable
protected NamedValueInfo createNamedValueInfo(MethodParameter parameter) { protected NamedValueInfo createNamedValueInfo(MethodParameter parameter) {
RequestAttribute annot = parameter.getParameterAnnotation(RequestAttribute.class); RequestAttribute annot = parameter.getParameterAnnotation(RequestAttribute.class);
return (annot == null ? null : return (annot == null ? null :

View File

@ -18,6 +18,7 @@ package org.springframework.web.service.invoker;
import org.springframework.core.MethodParameter; import org.springframework.core.MethodParameter;
import org.springframework.core.convert.ConversionService; import org.springframework.core.convert.ConversionService;
import org.springframework.lang.Nullable;
import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestHeader;
/** /**
@ -57,6 +58,7 @@ public class RequestHeaderArgumentResolver extends AbstractNamedValueArgumentRes
@Override @Override
@Nullable
protected NamedValueInfo createNamedValueInfo(MethodParameter parameter) { protected NamedValueInfo createNamedValueInfo(MethodParameter parameter) {
RequestHeader annot = parameter.getParameterAnnotation(RequestHeader.class); RequestHeader annot = parameter.getParameterAnnotation(RequestHeader.class);
return (annot == null ? null : return (annot == null ? null :

View File

@ -18,6 +18,7 @@ package org.springframework.web.service.invoker;
import org.springframework.core.MethodParameter; import org.springframework.core.MethodParameter;
import org.springframework.core.convert.ConversionService; import org.springframework.core.convert.ConversionService;
import org.springframework.lang.Nullable;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
/** /**
@ -60,6 +61,7 @@ public class RequestParamArgumentResolver extends AbstractNamedValueArgumentReso
@Override @Override
@Nullable
protected NamedValueInfo createNamedValueInfo(MethodParameter parameter) { protected NamedValueInfo createNamedValueInfo(MethodParameter parameter) {
RequestParam annot = parameter.getParameterAnnotation(RequestParam.class); RequestParam annot = parameter.getParameterAnnotation(RequestParam.class);
return (annot == null ? null : return (annot == null ? null :

View File

@ -78,6 +78,7 @@ public class RequestPartArgumentResolver extends AbstractNamedValueArgumentResol
@Override @Override
@Nullable
protected NamedValueInfo createNamedValueInfo(MethodParameter parameter) { protected NamedValueInfo createNamedValueInfo(MethodParameter parameter) {
RequestPart annot = parameter.getParameterAnnotation(RequestPart.class); RequestPart annot = parameter.getParameterAnnotation(RequestPart.class);
boolean isMultiPartFile = parameter.nestedIfOptional().getNestedParameterType().equals(MultipartFile.class); boolean isMultiPartFile = parameter.nestedIfOptional().getNestedParameterType().equals(MultipartFile.class);

View File

@ -1077,6 +1077,7 @@ final class HierarchicalUriComponents extends UriComponents {
} }
@Override @Override
@Nullable
public Object getValue(@Nullable String name) { public Object getValue(@Nullable String name) {
Object value = this.delegate.getValue(name); Object value = this.delegate.getValue(name);
if (ObjectUtils.isArray(value)) { if (ObjectUtils.isArray(value)) {

View File

@ -677,7 +677,7 @@ public class UriComponentsBuilder implements UriBuilder, Cloneable {
} }
@Override @Override
public UriComponentsBuilder queryParam(String name, Object... values) { public UriComponentsBuilder queryParam(String name, @Nullable Object... values) {
Assert.notNull(name, "Name must not be null"); Assert.notNull(name, "Name must not be null");
if (!ObjectUtils.isEmpty(values)) { if (!ObjectUtils.isEmpty(values)) {
for (Object value : values) { for (Object value : values) {
@ -927,6 +927,7 @@ public class UriComponentsBuilder implements UriBuilder, Cloneable {
} }
@Override @Override
@Nullable
public PathComponent build() { public PathComponent build() {
if (this.path.length() == 0) { if (this.path.length() == 0) {
return null; return null;
@ -977,6 +978,7 @@ public class UriComponentsBuilder implements UriBuilder, Cloneable {
} }
@Override @Override
@Nullable
public PathComponent build() { public PathComponent build() {
return (this.pathSegments.isEmpty() ? null : return (this.pathSegments.isEmpty() ? null :
new HierarchicalUriComponents.PathSegmentComponent(this.pathSegments)); new HierarchicalUriComponents.PathSegmentComponent(this.pathSegments));

View File

@ -540,7 +540,7 @@ public abstract class WebUtils {
* @param name the name of the attribute * @param name the name of the attribute
* @param value the suggested value of the attribute * @param value the suggested value of the attribute
*/ */
private static void exposeRequestAttributeIfNotPresent(ServletRequest request, String name, Object value) { private static void exposeRequestAttributeIfNotPresent(ServletRequest request, String name, @Nullable Object value) {
if (request.getAttribute(name) == null) { if (request.getAttribute(name) == null) {
request.setAttribute(name, value); request.setAttribute(name, value);
} }

View File

@ -18,6 +18,7 @@ package org.springframework.web.reactive.handler;
import org.springframework.core.annotation.AnnotatedElementUtils; import org.springframework.core.annotation.AnnotatedElementUtils;
import org.springframework.http.HttpStatusCode; import org.springframework.http.HttpStatusCode;
import org.springframework.lang.Nullable;
import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.server.handler.ResponseStatusExceptionHandler; import org.springframework.web.server.handler.ResponseStatusExceptionHandler;
@ -38,6 +39,7 @@ import org.springframework.web.server.handler.ResponseStatusExceptionHandler;
public class WebFluxResponseStatusExceptionHandler extends ResponseStatusExceptionHandler { public class WebFluxResponseStatusExceptionHandler extends ResponseStatusExceptionHandler {
@Override @Override
@Nullable
protected HttpStatusCode determineStatus(Throwable ex) { protected HttpStatusCode determineStatus(Throwable ex) {
HttpStatusCode statusCode = super.determineStatus(ex); HttpStatusCode statusCode = super.determineStatus(ex);
if (statusCode == null) { if (statusCode == null) {

View File

@ -66,6 +66,7 @@ public class RequestAttributeMethodArgumentResolver extends AbstractNamedValueSy
} }
@Override @Override
@Nullable
protected Object resolveNamedValue(String name, MethodParameter parameter, ServerWebExchange exchange) { protected Object resolveNamedValue(String name, MethodParameter parameter, ServerWebExchange exchange) {
Object value = exchange.getAttribute(name); Object value = exchange.getAttribute(name);
ReactiveAdapter toAdapter = getAdapterRegistry().getAdapter(parameter.getParameterType()); ReactiveAdapter toAdapter = getAdapterRegistry().getAdapter(parameter.getParameterType());

View File

@ -1215,7 +1215,7 @@ public abstract class FrameworkServlet extends HttpServletBean implements Applic
} }
} }
@Override @Override
public <T> void postProcess(NativeWebRequest webRequest, Callable<T> task, Object concurrentResult) { public <T> void postProcess(NativeWebRequest webRequest, Callable<T> task, @Nullable Object concurrentResult) {
HttpServletRequest request = webRequest.getNativeRequest(HttpServletRequest.class); HttpServletRequest request = webRequest.getNativeRequest(HttpServletRequest.class);
if (request != null) { if (request != null) {
resetContextHolders(request, null, null); resetContextHolders(request, null, null);

View File

@ -70,6 +70,7 @@ public class ServletModelAttributeMethodProcessor extends ModelAttributeMethodPr
* @see #createAttributeFromRequestValue * @see #createAttributeFromRequestValue
*/ */
@Override @Override
@Nullable
protected final Object createAttribute(String attributeName, MethodParameter parameter, protected final Object createAttribute(String attributeName, MethodParameter parameter,
WebDataBinderFactory binderFactory, NativeWebRequest request) throws Exception { WebDataBinderFactory binderFactory, NativeWebRequest request) throws Exception {

View File

@ -257,6 +257,7 @@ public class WebSocketHttpHeaders extends HttpHeaders {
} }
@Override @Override
@Nullable
public List<String> get(Object key) { public List<String> get(Object key) {
return this.headers.get(key); return this.headers.get(key);
} }

View File

@ -114,6 +114,7 @@ public class JettyWebSocketSession extends AbstractWebSocketSession<Session> {
} }
@Override @Override
@Nullable
public String getAcceptedProtocol() { public String getAcceptedProtocol() {
checkNativeSessionInitialized(); checkNativeSessionInitialized();
return this.acceptedProtocol; return this.acceptedProtocol;
@ -126,6 +127,7 @@ public class JettyWebSocketSession extends AbstractWebSocketSession<Session> {
} }
@Override @Override
@Nullable
public Principal getPrincipal() { public Principal getPrincipal() {
return this.user; return this.user;
} }

View File

@ -129,6 +129,7 @@ public class StandardWebSocketSession extends AbstractWebSocketSession<Session>
} }
@Override @Override
@Nullable
public String getAcceptedProtocol() { public String getAcceptedProtocol() {
checkNativeSessionInitialized(); checkNativeSessionInitialized();
return this.acceptedProtocol; return this.acceptedProtocol;
@ -141,6 +142,7 @@ public class StandardWebSocketSession extends AbstractWebSocketSession<Session>
} }
@Override @Override
@Nullable
public Principal getPrincipal() { public Principal getPrincipal() {
return this.user; return this.user;
} }

View File

@ -21,6 +21,7 @@ import java.util.List;
import jakarta.websocket.Extension; import jakarta.websocket.Extension;
import org.springframework.lang.Nullable;
import org.springframework.web.socket.WebSocketExtension; import org.springframework.web.socket.WebSocketExtension;
/** /**
@ -46,6 +47,7 @@ public class WebSocketToStandardExtensionAdapter implements Extension {
return paramName; return paramName;
} }
@Override @Override
@Nullable
public String getValue() { public String getValue() {
return extension.getParameters().get(paramName); return extension.getParameters().get(paramName);
} }

View File

@ -133,6 +133,7 @@ class MessageBrokerBeanDefinitionParser implements BeanDefinitionParser {
@Override @Override
@Nullable
public BeanDefinition parse(Element element, ParserContext context) { public BeanDefinition parse(Element element, ParserContext context) {
Object source = context.extractSource(element); Object source = context.extractSource(element);
CompositeComponentDefinition compDefinition = new CompositeComponentDefinition(element.getTagName(), source); CompositeComponentDefinition compDefinition = new CompositeComponentDefinition(element.getTagName(), source);

View File

@ -96,21 +96,25 @@ public class WebSocketSessionDecorator implements WebSocketSession {
} }
@Override @Override
@Nullable
public Principal getPrincipal() { public Principal getPrincipal() {
return this.delegate.getPrincipal(); return this.delegate.getPrincipal();
} }
@Override @Override
@Nullable
public InetSocketAddress getLocalAddress() { public InetSocketAddress getLocalAddress() {
return this.delegate.getLocalAddress(); return this.delegate.getLocalAddress();
} }
@Override @Override
@Nullable
public InetSocketAddress getRemoteAddress() { public InetSocketAddress getRemoteAddress() {
return this.delegate.getRemoteAddress(); return this.delegate.getRemoteAddress();
} }
@Override @Override
@Nullable
public String getAcceptedProtocol() { public String getAcceptedProtocol() {
return this.delegate.getAcceptedProtocol(); return this.delegate.getAcceptedProtocol();
} }

View File

@ -110,6 +110,7 @@ public abstract class AbstractClientSockJsSession implements WebSocketSession {
} }
@Override @Override
@Nullable
public Principal getPrincipal() { public Principal getPrincipal() {
return this.request.getUser(); return this.request.getUser();
} }

View File

@ -207,6 +207,7 @@ public class RestTemplateXhrTransport extends AbstractXhrTransport {
} }
@Override @Override
@Nullable
public Object extractData(ClientHttpResponse response) throws IOException { public Object extractData(ClientHttpResponse response) throws IOException {
HttpStatusCode httpStatus = response.getStatusCode(); HttpStatusCode httpStatus = response.getStatusCode();
if (httpStatus != HttpStatus.OK) { if (httpStatus != HttpStatus.OK) {

View File

@ -74,18 +74,21 @@ public class WebSocketClientSockJsSession extends AbstractClientSockJsSession im
} }
@Override @Override
@Nullable
public InetSocketAddress getLocalAddress() { public InetSocketAddress getLocalAddress() {
Assert.state(this.webSocketSession != null, "WebSocketSession not yet initialized"); Assert.state(this.webSocketSession != null, "WebSocketSession not yet initialized");
return this.webSocketSession.getLocalAddress(); return this.webSocketSession.getLocalAddress();
} }
@Override @Override
@Nullable
public InetSocketAddress getRemoteAddress() { public InetSocketAddress getRemoteAddress() {
Assert.state(this.webSocketSession != null, "WebSocketSession not yet initialized"); Assert.state(this.webSocketSession != null, "WebSocketSession not yet initialized");
return this.webSocketSession.getRemoteAddress(); return this.webSocketSession.getRemoteAddress();
} }
@Override @Override
@Nullable
public String getAcceptedProtocol() { public String getAcceptedProtocol() {
Assert.state(this.webSocketSession != null, "WebSocketSession not yet initialized"); Assert.state(this.webSocketSession != null, "WebSocketSession not yet initialized");
return this.webSocketSession.getAcceptedProtocol(); return this.webSocketSession.getAcceptedProtocol();

View File

@ -24,6 +24,7 @@ import java.util.concurrent.CompletableFuture;
import org.springframework.http.HttpHeaders; import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.web.socket.CloseStatus; import org.springframework.web.socket.CloseStatus;
import org.springframework.web.socket.TextMessage; import org.springframework.web.socket.TextMessage;
@ -96,17 +97,20 @@ public class XhrClientSockJsSession extends AbstractClientSockJsSession {
} }
@Override @Override
@Nullable
public InetSocketAddress getLocalAddress() { public InetSocketAddress getLocalAddress() {
return null; return null;
} }
@Override @Override
@Nullable
public InetSocketAddress getRemoteAddress() { public InetSocketAddress getRemoteAddress() {
URI uri = getUri(); URI uri = getUri();
return (uri != null ? new InetSocketAddress(uri.getHost(), uri.getPort()) : null); return (uri != null ? new InetSocketAddress(uri.getHost(), uri.getPort()) : null);
} }
@Override @Override
@Nullable
public String getAcceptedProtocol() { public String getAcceptedProtocol() {
return null; return null;
} }

View File

@ -341,6 +341,7 @@ public abstract class AbstractSockJsService implements SockJsService, CorsConfig
* @since 4.1.2 * @since 4.1.2
*/ */
@SuppressWarnings("ConstantConditions") @SuppressWarnings("ConstantConditions")
@Nullable
public Collection<String> getAllowedOrigins() { public Collection<String> getAllowedOrigins() {
return this.corsConfiguration.getAllowedOrigins(); return this.corsConfiguration.getAllowedOrigins();
} }
@ -363,6 +364,7 @@ public abstract class AbstractSockJsService implements SockJsService, CorsConfig
* @since 5.3.2 * @since 5.3.2
*/ */
@SuppressWarnings("ConstantConditions") @SuppressWarnings("ConstantConditions")
@Nullable
public Collection<String> getAllowedOriginPatterns() { public Collection<String> getAllowedOriginPatterns() {
return this.corsConfiguration.getAllowedOriginPatterns(); return this.corsConfiguration.getAllowedOriginPatterns();
} }
@ -415,8 +417,8 @@ public abstract class AbstractSockJsService implements SockJsService, CorsConfig
} }
else if (sockJsPath.matches("/iframe[0-9-.a-z_]*.html")) { else if (sockJsPath.matches("/iframe[0-9-.a-z_]*.html")) {
if (!getAllowedOrigins().isEmpty() && !getAllowedOrigins().contains("*") || if (!CollectionUtils.isEmpty(getAllowedOrigins()) && !getAllowedOrigins().contains("*") ||
!getAllowedOriginPatterns().isEmpty()) { !CollectionUtils.isEmpty(getAllowedOriginPatterns())) {
if (requestInfo != null) { if (requestInfo != null) {
logger.debug("Iframe support is disabled when an origin check is required. " + logger.debug("Iframe support is disabled when an origin check is required. " +
"Ignoring transport request: " + requestInfo); "Ignoring transport request: " + requestInfo);
@ -424,7 +426,7 @@ public abstract class AbstractSockJsService implements SockJsService, CorsConfig
response.setStatusCode(HttpStatus.NOT_FOUND); response.setStatusCode(HttpStatus.NOT_FOUND);
return; return;
} }
if (getAllowedOrigins().isEmpty()) { if (CollectionUtils.isEmpty(getAllowedOrigins())) {
response.getHeaders().add(XFRAME_OPTIONS_HEADER, "SAMEORIGIN"); response.getHeaders().add(XFRAME_OPTIONS_HEADER, "SAMEORIGIN");
} }
if (requestInfo != null) { if (requestInfo != null) {

View File

@ -346,8 +346,8 @@ public class TransportHandlingSockJsService extends AbstractSockJsService implem
return false; return false;
} }
if (!getAllowedOrigins().isEmpty() && !getAllowedOrigins().contains("*") || if (!CollectionUtils.isEmpty(getAllowedOrigins()) && !getAllowedOrigins().contains("*") ||
!getAllowedOriginPatterns().isEmpty()) { !CollectionUtils.isEmpty(getAllowedOriginPatterns())) {
TransportType transportType = TransportType.fromValue(transport); TransportType transportType = TransportType.fromValue(transport);
if (transportType == null || !transportType.supportsOrigin()) { if (transportType == null || !transportType.supportsOrigin()) {
if (logger.isWarnEnabled()) { if (logger.isWarnEnabled()) {

View File

@ -83,24 +83,28 @@ public class WebSocketServerSockJsSession extends AbstractSockJsSession implemen
} }
@Override @Override
@Nullable
public Principal getPrincipal() { public Principal getPrincipal() {
Assert.state(this.webSocketSession != null, "WebSocketSession not yet initialized"); Assert.state(this.webSocketSession != null, "WebSocketSession not yet initialized");
return this.webSocketSession.getPrincipal(); return this.webSocketSession.getPrincipal();
} }
@Override @Override
@Nullable
public InetSocketAddress getLocalAddress() { public InetSocketAddress getLocalAddress() {
Assert.state(this.webSocketSession != null, "WebSocketSession not yet initialized"); Assert.state(this.webSocketSession != null, "WebSocketSession not yet initialized");
return this.webSocketSession.getLocalAddress(); return this.webSocketSession.getLocalAddress();
} }
@Override @Override
@Nullable
public InetSocketAddress getRemoteAddress() { public InetSocketAddress getRemoteAddress() {
Assert.state(this.webSocketSession != null, "WebSocketSession not yet initialized"); Assert.state(this.webSocketSession != null, "WebSocketSession not yet initialized");
return this.webSocketSession.getRemoteAddress(); return this.webSocketSession.getRemoteAddress();
} }
@Override @Override
@Nullable
public String getAcceptedProtocol() { public String getAcceptedProtocol() {
Assert.state(this.webSocketSession != null, "WebSocketSession not yet initialized"); Assert.state(this.webSocketSession != null, "WebSocketSession not yet initialized");
return this.webSocketSession.getAcceptedProtocol(); return this.webSocketSession.getAcceptedProtocol();