diff --git a/spring-web/src/main/java/org/springframework/web/DefaultErrorResponseBuilder.java b/spring-web/src/main/java/org/springframework/web/DefaultErrorResponseBuilder.java index 6bf4f156a933..2d564465863c 100644 --- a/spring-web/src/main/java/org/springframework/web/DefaultErrorResponseBuilder.java +++ b/spring-web/src/main/java/org/springframework/web/DefaultErrorResponseBuilder.java @@ -211,6 +211,7 @@ public String getDetailMessageCode() { } @Override + @Nullable public Object[] getDetailMessageArguments() { return this.detailMessageArguments; } diff --git a/spring-web/src/main/java/org/springframework/web/ErrorResponseException.java b/spring-web/src/main/java/org/springframework/web/ErrorResponseException.java index 6e6a8165ddf6..714abbb8b556 100644 --- a/spring-web/src/main/java/org/springframework/web/ErrorResponseException.java +++ b/spring-web/src/main/java/org/springframework/web/ErrorResponseException.java @@ -165,6 +165,7 @@ public String getDetailMessageCode() { } @Override + @Nullable public Object[] getDetailMessageArguments() { return this.messageDetailArguments; } diff --git a/spring-web/src/main/java/org/springframework/web/HttpMediaTypeException.java b/spring-web/src/main/java/org/springframework/web/HttpMediaTypeException.java index de550874271b..70febbdfd55f 100644 --- a/spring-web/src/main/java/org/springframework/web/HttpMediaTypeException.java +++ b/spring-web/src/main/java/org/springframework/web/HttpMediaTypeException.java @@ -73,7 +73,7 @@ protected HttpMediaTypeException(String message, List supportedMediaT * resolving the problem "detail" through a {@code MessageSource} * @since 6.0 */ - protected HttpMediaTypeException(String message, List supportedMediaTypes, + protected HttpMediaTypeException(@Nullable String message, List supportedMediaTypes, @Nullable String messageDetailCode, @Nullable Object[] messageDetailArguments) { super(message); @@ -102,6 +102,7 @@ public String getDetailMessageCode() { } @Override + @Nullable public Object[] getDetailMessageArguments() { return this.messageDetailArguments; } diff --git a/spring-web/src/main/java/org/springframework/web/HttpMediaTypeNotSupportedException.java b/spring-web/src/main/java/org/springframework/web/HttpMediaTypeNotSupportedException.java index d9db78b666c4..4ce57138a5d3 100644 --- a/spring-web/src/main/java/org/springframework/web/HttpMediaTypeNotSupportedException.java +++ b/spring-web/src/main/java/org/springframework/web/HttpMediaTypeNotSupportedException.java @@ -63,7 +63,7 @@ public HttpMediaTypeNotSupportedException(String message) { * @param mediaTypes list of supported media types * @since 6.0.5 */ - public HttpMediaTypeNotSupportedException(String message, List mediaTypes) { + public HttpMediaTypeNotSupportedException(@Nullable String message, List mediaTypes) { super(message, mediaTypes, PARSE_ERROR_DETAIL_CODE, null); this.contentType = null; this.httpMethod = null; diff --git a/spring-web/src/main/java/org/springframework/web/accept/ServletPathExtensionContentNegotiationStrategy.java b/spring-web/src/main/java/org/springframework/web/accept/ServletPathExtensionContentNegotiationStrategy.java index 485727d718db..fee82413c177 100644 --- a/spring-web/src/main/java/org/springframework/web/accept/ServletPathExtensionContentNegotiationStrategy.java +++ b/spring-web/src/main/java/org/springframework/web/accept/ServletPathExtensionContentNegotiationStrategy.java @@ -99,6 +99,7 @@ protected MediaType handleNoMatch(NativeWebRequest webRequest, String extension) * @since 4.3 */ @Override + @Nullable public MediaType getMediaTypeForResource(Resource resource) { MediaType mediaType = null; String mimeType = this.servletContext.getMimeType(resource.getFilename()); diff --git a/spring-web/src/main/java/org/springframework/web/bind/ServletRequestBindingException.java b/spring-web/src/main/java/org/springframework/web/bind/ServletRequestBindingException.java index a18841424958..b0ca83d61cf0 100644 --- a/spring-web/src/main/java/org/springframework/web/bind/ServletRequestBindingException.java +++ b/spring-web/src/main/java/org/springframework/web/bind/ServletRequestBindingException.java @@ -50,7 +50,7 @@ public class ServletRequestBindingException extends ServletException implements * Constructor with a message only. * @param msg the detail message */ - public ServletRequestBindingException(String msg) { + public ServletRequestBindingException(@Nullable String msg) { this(msg, null, null); } @@ -59,7 +59,7 @@ public ServletRequestBindingException(String msg) { * @param msg the detail message * @param cause the root cause */ - public ServletRequestBindingException(String msg, Throwable cause) { + public ServletRequestBindingException(@Nullable String msg, @Nullable Throwable cause) { this(msg, cause, null, null); } @@ -73,7 +73,7 @@ public ServletRequestBindingException(String msg, Throwable cause) { * @since 6.0 */ protected ServletRequestBindingException( - String msg, @Nullable String messageDetailCode, @Nullable Object[] messageDetailArguments) { + @Nullable String msg, @Nullable String messageDetailCode, @Nullable Object[] messageDetailArguments) { this(msg, null, messageDetailCode, messageDetailArguments); } @@ -88,7 +88,7 @@ protected ServletRequestBindingException( * resolving the problem "detail" through a {@code MessageSource} * @since 6.0 */ - protected ServletRequestBindingException(String msg, @Nullable Throwable cause, + protected ServletRequestBindingException(@Nullable String msg, @Nullable Throwable cause, @Nullable String messageDetailCode, @Nullable Object[] messageDetailArguments) { super(msg, cause); @@ -118,6 +118,7 @@ public String getDetailMessageCode() { } @Override + @Nullable public Object[] getDetailMessageArguments() { return this.messageDetailArguments; } diff --git a/spring-web/src/main/java/org/springframework/web/bind/support/BindParamNameResolver.java b/spring-web/src/main/java/org/springframework/web/bind/support/BindParamNameResolver.java index 8fc8bca0ee75..5b50bb851553 100644 --- a/spring-web/src/main/java/org/springframework/web/bind/support/BindParamNameResolver.java +++ b/spring-web/src/main/java/org/springframework/web/bind/support/BindParamNameResolver.java @@ -17,6 +17,7 @@ package org.springframework.web.bind.support; import org.springframework.core.MethodParameter; +import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; import org.springframework.validation.DataBinder; import org.springframework.web.bind.annotation.BindParam; @@ -32,6 +33,7 @@ public final class BindParamNameResolver implements DataBinder.NameResolver { @Override + @Nullable public String resolveName(MethodParameter parameter) { BindParam bindParam = parameter.getParameterAnnotation(BindParam.class); if (bindParam != null) { diff --git a/spring-web/src/main/java/org/springframework/web/bind/support/WebExchangeDataBinder.java b/spring-web/src/main/java/org/springframework/web/bind/support/WebExchangeDataBinder.java index e169a2cd6a02..10cc5a8b2639 100644 --- a/spring-web/src/main/java/org/springframework/web/bind/support/WebExchangeDataBinder.java +++ b/spring-web/src/main/java/org/springframework/web/bind/support/WebExchangeDataBinder.java @@ -162,6 +162,7 @@ protected static void addBindValue(Map params, String key, List< private record MapValueResolver(Map map) implements ValueResolver { @Override + @Nullable public Object resolveValue(String name, Class type) { return this.map.get(name); } diff --git a/spring-web/src/main/java/org/springframework/web/client/HttpMessageConverterExtractor.java b/spring-web/src/main/java/org/springframework/web/client/HttpMessageConverterExtractor.java index af7580cbe1d7..0efb72375d4e 100644 --- a/spring-web/src/main/java/org/springframework/web/client/HttpMessageConverterExtractor.java +++ b/spring-web/src/main/java/org/springframework/web/client/HttpMessageConverterExtractor.java @@ -84,6 +84,7 @@ public HttpMessageConverterExtractor(Type responseType, List T exchangeForBody(HttpRequestValues values, ParameterizedTypeReference bodyType) { return newRequest(values).retrieve().body(bodyType); } diff --git a/spring-web/src/main/java/org/springframework/web/context/request/FacesRequestAttributes.java b/spring-web/src/main/java/org/springframework/web/context/request/FacesRequestAttributes.java index c936d89277c3..24961bb68e5d 100644 --- a/spring-web/src/main/java/org/springframework/web/context/request/FacesRequestAttributes.java +++ b/spring-web/src/main/java/org/springframework/web/context/request/FacesRequestAttributes.java @@ -24,6 +24,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ReflectionUtils; import org.springframework.util.StringUtils; @@ -102,6 +103,7 @@ protected Map getAttributeMap(int scope) { @Override + @Nullable public Object getAttribute(String name, int scope) { return getAttributeMap(scope).get(name); } @@ -130,6 +132,7 @@ public void registerDestructionCallback(String name, Runnable callback, int scop } @Override + @Nullable public Object resolveReference(String key) { return switch (key) { case REFERENCE_REQUEST -> getExternalContext().getRequest(); diff --git a/spring-web/src/main/java/org/springframework/web/context/request/FacesWebRequest.java b/spring-web/src/main/java/org/springframework/web/context/request/FacesWebRequest.java index 733a6e8405e6..b8163ad27381 100644 --- a/spring-web/src/main/java/org/springframework/web/context/request/FacesWebRequest.java +++ b/spring-web/src/main/java/org/springframework/web/context/request/FacesWebRequest.java @@ -58,6 +58,7 @@ public Object getNativeResponse() { } @Override + @Nullable @SuppressWarnings("unchecked") public T getNativeRequest(@Nullable Class requiredType) { if (requiredType != null) { @@ -70,6 +71,7 @@ public T getNativeRequest(@Nullable Class requiredType) { } @Override + @Nullable @SuppressWarnings("unchecked") public T getNativeResponse(@Nullable Class requiredType) { if (requiredType != null) { diff --git a/spring-web/src/main/java/org/springframework/web/context/request/ServletRequestAttributes.java b/spring-web/src/main/java/org/springframework/web/context/request/ServletRequestAttributes.java index a767b0b98f52..52cddccba745 100644 --- a/spring-web/src/main/java/org/springframework/web/context/request/ServletRequestAttributes.java +++ b/spring-web/src/main/java/org/springframework/web/context/request/ServletRequestAttributes.java @@ -143,6 +143,7 @@ private HttpSession obtainSession() { @Override + @Nullable public Object getAttribute(String name, int scope) { if (scope == SCOPE_REQUEST) { if (!isRequestActive()) { @@ -242,6 +243,7 @@ public void registerDestructionCallback(String name, Runnable callback, int scop } @Override + @Nullable public Object resolveReference(String key) { if (REFERENCE_REQUEST.equals(key)) { return this.request; diff --git a/spring-web/src/main/java/org/springframework/web/context/request/ServletWebRequest.java b/spring-web/src/main/java/org/springframework/web/context/request/ServletWebRequest.java index 8545894cfff0..f8f2b4a3beac 100644 --- a/spring-web/src/main/java/org/springframework/web/context/request/ServletWebRequest.java +++ b/spring-web/src/main/java/org/springframework/web/context/request/ServletWebRequest.java @@ -98,16 +98,19 @@ public Object getNativeRequest() { } @Override + @Nullable public Object getNativeResponse() { return getResponse(); } @Override + @Nullable public T getNativeRequest(@Nullable Class requiredType) { return WebUtils.getNativeRequest(getRequest(), requiredType); } @Override + @Nullable public T getNativeResponse(@Nullable Class requiredType) { HttpServletResponse response = getResponse(); return (response != null ? WebUtils.getNativeResponse(response, requiredType) : null); diff --git a/spring-web/src/main/java/org/springframework/web/context/request/async/StandardServletAsyncWebRequest.java b/spring-web/src/main/java/org/springframework/web/context/request/async/StandardServletAsyncWebRequest.java index 67e137a55d5e..b8f767c57725 100644 --- a/spring-web/src/main/java/org/springframework/web/context/request/async/StandardServletAsyncWebRequest.java +++ b/spring-web/src/main/java/org/springframework/web/context/request/async/StandardServletAsyncWebRequest.java @@ -101,7 +101,7 @@ public StandardServletAsyncWebRequest(HttpServletRequest request, HttpServletRes * container processing thread has exited. */ @Override - public void setTimeout(Long timeout) { + public void setTimeout(@Nullable Long timeout) { Assert.state(!isAsyncStarted(), "Cannot change the timeout with concurrent handling in progress"); this.timeout = timeout; } diff --git a/spring-web/src/main/java/org/springframework/web/context/support/ServletContextAttributeFactoryBean.java b/spring-web/src/main/java/org/springframework/web/context/support/ServletContextAttributeFactoryBean.java index af64835df278..84f927773881 100644 --- a/spring-web/src/main/java/org/springframework/web/context/support/ServletContextAttributeFactoryBean.java +++ b/spring-web/src/main/java/org/springframework/web/context/support/ServletContextAttributeFactoryBean.java @@ -77,6 +77,7 @@ public Object getObject() throws Exception { } @Override + @Nullable public Class getObjectType() { return (this.attribute != null ? this.attribute.getClass() : null); } diff --git a/spring-web/src/main/java/org/springframework/web/context/support/StaticWebApplicationContext.java b/spring-web/src/main/java/org/springframework/web/context/support/StaticWebApplicationContext.java index 7906d8820bc5..a03c975d9e15 100644 --- a/spring-web/src/main/java/org/springframework/web/context/support/StaticWebApplicationContext.java +++ b/spring-web/src/main/java/org/springframework/web/context/support/StaticWebApplicationContext.java @@ -139,6 +139,7 @@ public void setConfigLocations(String... configLocations) { } @Override + @Nullable public String[] getConfigLocations() { return null; } diff --git a/spring-web/src/main/java/org/springframework/web/cors/DefaultCorsProcessor.java b/spring-web/src/main/java/org/springframework/web/cors/DefaultCorsProcessor.java index c134d806df9b..73ef4679b4dd 100644 --- a/spring-web/src/main/java/org/springframework/web/cors/DefaultCorsProcessor.java +++ b/spring-web/src/main/java/org/springframework/web/cors/DefaultCorsProcessor.java @@ -155,7 +155,7 @@ protected boolean handleInternal(ServerHttpRequest request, ServerHttpResponse r responseHeaders.setAccessControlAllowMethods(allowMethods); } - if (preFlightRequest && !allowHeaders.isEmpty()) { + if (preFlightRequest && !CollectionUtils.isEmpty(allowHeaders)) { responseHeaders.setAccessControlAllowHeaders(allowHeaders); } diff --git a/spring-web/src/main/java/org/springframework/web/cors/reactive/DefaultCorsProcessor.java b/spring-web/src/main/java/org/springframework/web/cors/reactive/DefaultCorsProcessor.java index a259efbb8e74..d15dcd122fe0 100644 --- a/spring-web/src/main/java/org/springframework/web/cors/reactive/DefaultCorsProcessor.java +++ b/spring-web/src/main/java/org/springframework/web/cors/reactive/DefaultCorsProcessor.java @@ -153,7 +153,7 @@ protected boolean handleInternal(ServerWebExchange exchange, responseHeaders.setAccessControlAllowMethods(allowMethods); } - if (preFlightRequest && !allowHeaders.isEmpty()) { + if (preFlightRequest && !CollectionUtils.isEmpty(allowHeaders)) { responseHeaders.setAccessControlAllowHeaders(allowHeaders); } diff --git a/spring-web/src/main/java/org/springframework/web/filter/ForwardedHeaderFilter.java b/spring-web/src/main/java/org/springframework/web/filter/ForwardedHeaderFilter.java index 8de8b0503605..49fc6d8eee13 100644 --- a/spring-web/src/main/java/org/springframework/web/filter/ForwardedHeaderFilter.java +++ b/spring-web/src/main/java/org/springframework/web/filter/ForwardedHeaderFilter.java @@ -340,6 +340,7 @@ public int getRemotePort() { @SuppressWarnings("DataFlowIssue") @Override + @Nullable public Object getAttribute(String name) { if (name.equals(WebUtils.ERROR_REQUEST_URI_ATTRIBUTE)) { return this.forwardedPrefixExtractor.getErrorRequestUri(); diff --git a/spring-web/src/main/java/org/springframework/web/filter/ServerHttpObservationFilter.java b/spring-web/src/main/java/org/springframework/web/filter/ServerHttpObservationFilter.java index 3ca50f609b59..effaf0553de3 100644 --- a/spring-web/src/main/java/org/springframework/web/filter/ServerHttpObservationFilter.java +++ b/spring-web/src/main/java/org/springframework/web/filter/ServerHttpObservationFilter.java @@ -139,6 +139,7 @@ private Observation createOrFetchObservation(HttpServletRequest request, HttpSer return observation; } + @Nullable private Throwable unwrapServletException(Throwable ex) { return (ex instanceof ServletException) ? ex.getCause() : ex; } diff --git a/spring-web/src/main/java/org/springframework/web/method/annotation/ExceptionHandlerMethodResolver.java b/spring-web/src/main/java/org/springframework/web/method/annotation/ExceptionHandlerMethodResolver.java index 8850d58be450..36673d2ece69 100644 --- a/spring-web/src/main/java/org/springframework/web/method/annotation/ExceptionHandlerMethodResolver.java +++ b/spring-web/src/main/java/org/springframework/web/method/annotation/ExceptionHandlerMethodResolver.java @@ -174,6 +174,7 @@ public Method resolveMethodByExceptionType(Class exceptionT * Return the {@link Method} mapped to the given exception type, or * {@link #NO_MATCHING_EXCEPTION_HANDLER_METHOD} if none. */ + @Nullable private Method getMappedMethod(Class exceptionType) { List> matches = new ArrayList<>(); for (Class mappedException : this.mappedMethods.keySet()) { diff --git a/spring-web/src/main/java/org/springframework/web/method/annotation/MethodArgumentConversionNotSupportedException.java b/spring-web/src/main/java/org/springframework/web/method/annotation/MethodArgumentConversionNotSupportedException.java index 8c070faa3d4a..3043f3364358 100644 --- a/spring-web/src/main/java/org/springframework/web/method/annotation/MethodArgumentConversionNotSupportedException.java +++ b/spring-web/src/main/java/org/springframework/web/method/annotation/MethodArgumentConversionNotSupportedException.java @@ -37,7 +37,7 @@ public class MethodArgumentConversionNotSupportedException extends ConversionNot 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); this.name = name; diff --git a/spring-web/src/main/java/org/springframework/web/method/annotation/MethodArgumentTypeMismatchException.java b/spring-web/src/main/java/org/springframework/web/method/annotation/MethodArgumentTypeMismatchException.java index 4f715ff0eb56..bad7e75bde7d 100644 --- a/spring-web/src/main/java/org/springframework/web/method/annotation/MethodArgumentTypeMismatchException.java +++ b/spring-web/src/main/java/org/springframework/web/method/annotation/MethodArgumentTypeMismatchException.java @@ -37,7 +37,7 @@ public class MethodArgumentTypeMismatchException extends TypeMismatchException { 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); this.name = name; diff --git a/spring-web/src/main/java/org/springframework/web/multipart/MultipartFileResource.java b/spring-web/src/main/java/org/springframework/web/multipart/MultipartFileResource.java index 141ca407f093..d710062e0680 100644 --- a/spring-web/src/main/java/org/springframework/web/multipart/MultipartFileResource.java +++ b/spring-web/src/main/java/org/springframework/web/multipart/MultipartFileResource.java @@ -65,6 +65,7 @@ public long contentLength() { } @Override + @Nullable public String getFilename() { return this.multipartFile.getOriginalFilename(); } diff --git a/spring-web/src/main/java/org/springframework/web/multipart/support/DefaultMultipartHttpServletRequest.java b/spring-web/src/main/java/org/springframework/web/multipart/support/DefaultMultipartHttpServletRequest.java index 3ac4ddeed77d..609837234ba0 100644 --- a/spring-web/src/main/java/org/springframework/web/multipart/support/DefaultMultipartHttpServletRequest.java +++ b/spring-web/src/main/java/org/springframework/web/multipart/support/DefaultMultipartHttpServletRequest.java @@ -130,6 +130,7 @@ public Map getParameterMap() { } @Override + @Nullable public String getMultipartContentType(String paramOrFileName) { MultipartFile file = getFile(paramOrFileName); if (file != null) { @@ -141,6 +142,7 @@ public String getMultipartContentType(String paramOrFileName) { } @Override + @Nullable public HttpHeaders getMultipartHeaders(String paramOrFileName) { String contentType = getMultipartContentType(paramOrFileName); if (contentType != null) { @@ -167,6 +169,7 @@ protected final void setMultipartParameters(Map multipartParam * lazily initializing it if necessary. * @see #initializeMultipart() */ + @SuppressWarnings("NullAway") protected Map getMultipartParameters() { if (this.multipartParameters == null) { initializeMultipart(); @@ -187,6 +190,7 @@ protected final void setMultipartParameterContentTypes(Map multi * lazily initializing it if necessary. * @see #initializeMultipart() */ + @SuppressWarnings("NullAway") protected Map getMultipartParameterContentTypes() { if (this.multipartParameterContentTypes == null) { initializeMultipart(); diff --git a/spring-web/src/main/java/org/springframework/web/multipart/support/StandardMultipartHttpServletRequest.java b/spring-web/src/main/java/org/springframework/web/multipart/support/StandardMultipartHttpServletRequest.java index 6d7bd180bfc5..e0d1a3a68d9c 100644 --- a/spring-web/src/main/java/org/springframework/web/multipart/support/StandardMultipartHttpServletRequest.java +++ b/spring-web/src/main/java/org/springframework/web/multipart/support/StandardMultipartHttpServletRequest.java @@ -176,6 +176,7 @@ public Map getParameterMap() { } @Override + @Nullable public String getMultipartContentType(String paramOrFileName) { try { Part part = getPart(paramOrFileName); @@ -187,6 +188,7 @@ public String getMultipartContentType(String paramOrFileName) { } @Override + @Nullable public HttpHeaders getMultipartHeaders(String paramOrFileName) { try { Part part = getPart(paramOrFileName); diff --git a/spring-web/src/main/java/org/springframework/web/server/ServerWebExchangeDecorator.java b/spring-web/src/main/java/org/springframework/web/server/ServerWebExchangeDecorator.java index 5111ea1ee864..b69c18599a47 100644 --- a/spring-web/src/main/java/org/springframework/web/server/ServerWebExchangeDecorator.java +++ b/spring-web/src/main/java/org/springframework/web/server/ServerWebExchangeDecorator.java @@ -94,6 +94,7 @@ public LocaleContext getLocaleContext() { } @Override + @Nullable public ApplicationContext getApplicationContext() { return getDelegate().getApplicationContext(); } diff --git a/spring-web/src/main/java/org/springframework/web/service/invoker/CookieValueArgumentResolver.java b/spring-web/src/main/java/org/springframework/web/service/invoker/CookieValueArgumentResolver.java index 84a00aa1a80e..6b987351bdc3 100644 --- a/spring-web/src/main/java/org/springframework/web/service/invoker/CookieValueArgumentResolver.java +++ b/spring-web/src/main/java/org/springframework/web/service/invoker/CookieValueArgumentResolver.java @@ -18,6 +18,7 @@ import org.springframework.core.MethodParameter; import org.springframework.core.convert.ConversionService; +import org.springframework.lang.Nullable; import org.springframework.web.bind.annotation.CookieValue; /** @@ -56,6 +57,7 @@ public CookieValueArgumentResolver(ConversionService conversionService) { @Override + @Nullable protected NamedValueInfo createNamedValueInfo(MethodParameter parameter) { CookieValue annot = parameter.getParameterAnnotation(CookieValue.class); return (annot == null ? null : diff --git a/spring-web/src/main/java/org/springframework/web/service/invoker/HttpRequestValues.java b/spring-web/src/main/java/org/springframework/web/service/invoker/HttpRequestValues.java index 1a5fcea56087..12598fb22a00 100644 --- a/spring-web/src/main/java/org/springframework/web/service/invoker/HttpRequestValues.java +++ b/spring-web/src/main/java/org/springframework/web/service/invoker/HttpRequestValues.java @@ -408,7 +408,7 @@ public Builder addAttribute(String name, Object value) { /** * Set the request body as an Object to be serialized. */ - public void setBodyValue(Object bodyValue) { + public void setBodyValue(@Nullable Object bodyValue) { this.bodyValue = bodyValue; } diff --git a/spring-web/src/main/java/org/springframework/web/service/invoker/HttpServiceProxyFactory.java b/spring-web/src/main/java/org/springframework/web/service/invoker/HttpServiceProxyFactory.java index 6737aef14fee..5a0e6f7b89ff 100644 --- a/spring-web/src/main/java/org/springframework/web/service/invoker/HttpServiceProxyFactory.java +++ b/spring-web/src/main/java/org/springframework/web/service/invoker/HttpServiceProxyFactory.java @@ -294,6 +294,7 @@ private HttpServiceMethodInterceptor(List methods) { } @Override + @Nullable public Object invoke(MethodInvocation invocation) throws Throwable { Method method = invocation.getMethod(); HttpServiceMethod httpServiceMethod = this.httpServiceMethods.get(method); diff --git a/spring-web/src/main/java/org/springframework/web/service/invoker/PathVariableArgumentResolver.java b/spring-web/src/main/java/org/springframework/web/service/invoker/PathVariableArgumentResolver.java index 041894449b84..668e4fd4b5de 100644 --- a/spring-web/src/main/java/org/springframework/web/service/invoker/PathVariableArgumentResolver.java +++ b/spring-web/src/main/java/org/springframework/web/service/invoker/PathVariableArgumentResolver.java @@ -18,6 +18,7 @@ import org.springframework.core.MethodParameter; import org.springframework.core.convert.ConversionService; +import org.springframework.lang.Nullable; import org.springframework.web.bind.annotation.PathVariable; /** @@ -48,6 +49,7 @@ public PathVariableArgumentResolver(ConversionService conversionService) { @Override + @Nullable protected NamedValueInfo createNamedValueInfo(MethodParameter parameter) { PathVariable annot = parameter.getParameterAnnotation(PathVariable.class); return (annot == null ? null : diff --git a/spring-web/src/main/java/org/springframework/web/service/invoker/ReactiveHttpRequestValues.java b/spring-web/src/main/java/org/springframework/web/service/invoker/ReactiveHttpRequestValues.java index 55a07e979d37..daf33cb0bf9e 100644 --- a/spring-web/src/main/java/org/springframework/web/service/invoker/ReactiveHttpRequestValues.java +++ b/spring-web/src/main/java/org/springframework/web/service/invoker/ReactiveHttpRequestValues.java @@ -221,7 +221,7 @@ public > Builder addRequestPart(String name, P publish * {@linkplain #setBodyPublisher(Publisher, ParameterizedTypeReference)}. */ @Override - public void setBodyValue(Object bodyValue) { + public void setBodyValue(@Nullable Object bodyValue) { super.setBodyValue(bodyValue); this.body = null; this.bodyElementType = null; diff --git a/spring-web/src/main/java/org/springframework/web/service/invoker/RequestAttributeArgumentResolver.java b/spring-web/src/main/java/org/springframework/web/service/invoker/RequestAttributeArgumentResolver.java index 9aa75b9dcb84..b99f6f49b846 100644 --- a/spring-web/src/main/java/org/springframework/web/service/invoker/RequestAttributeArgumentResolver.java +++ b/spring-web/src/main/java/org/springframework/web/service/invoker/RequestAttributeArgumentResolver.java @@ -17,6 +17,7 @@ package org.springframework.web.service.invoker; import org.springframework.core.MethodParameter; +import org.springframework.lang.Nullable; import org.springframework.web.bind.annotation.RequestAttribute; /** @@ -40,6 +41,7 @@ public class RequestAttributeArgumentResolver extends AbstractNamedValueArgument @Override + @Nullable protected NamedValueInfo createNamedValueInfo(MethodParameter parameter) { RequestAttribute annot = parameter.getParameterAnnotation(RequestAttribute.class); return (annot == null ? null : diff --git a/spring-web/src/main/java/org/springframework/web/service/invoker/RequestHeaderArgumentResolver.java b/spring-web/src/main/java/org/springframework/web/service/invoker/RequestHeaderArgumentResolver.java index 9c0d566c3d6f..40a1523de6bf 100644 --- a/spring-web/src/main/java/org/springframework/web/service/invoker/RequestHeaderArgumentResolver.java +++ b/spring-web/src/main/java/org/springframework/web/service/invoker/RequestHeaderArgumentResolver.java @@ -18,6 +18,7 @@ import org.springframework.core.MethodParameter; import org.springframework.core.convert.ConversionService; +import org.springframework.lang.Nullable; import org.springframework.web.bind.annotation.RequestHeader; /** @@ -57,6 +58,7 @@ public RequestHeaderArgumentResolver(ConversionService conversionService) { @Override + @Nullable protected NamedValueInfo createNamedValueInfo(MethodParameter parameter) { RequestHeader annot = parameter.getParameterAnnotation(RequestHeader.class); return (annot == null ? null : diff --git a/spring-web/src/main/java/org/springframework/web/service/invoker/RequestParamArgumentResolver.java b/spring-web/src/main/java/org/springframework/web/service/invoker/RequestParamArgumentResolver.java index 2c3bb304fd03..ca72b532bcac 100644 --- a/spring-web/src/main/java/org/springframework/web/service/invoker/RequestParamArgumentResolver.java +++ b/spring-web/src/main/java/org/springframework/web/service/invoker/RequestParamArgumentResolver.java @@ -18,6 +18,7 @@ import org.springframework.core.MethodParameter; import org.springframework.core.convert.ConversionService; +import org.springframework.lang.Nullable; import org.springframework.web.bind.annotation.RequestParam; /** @@ -60,6 +61,7 @@ public RequestParamArgumentResolver(ConversionService conversionService) { @Override + @Nullable protected NamedValueInfo createNamedValueInfo(MethodParameter parameter) { RequestParam annot = parameter.getParameterAnnotation(RequestParam.class); return (annot == null ? null : diff --git a/spring-web/src/main/java/org/springframework/web/service/invoker/RequestPartArgumentResolver.java b/spring-web/src/main/java/org/springframework/web/service/invoker/RequestPartArgumentResolver.java index a35900e540e4..77180350d693 100644 --- a/spring-web/src/main/java/org/springframework/web/service/invoker/RequestPartArgumentResolver.java +++ b/spring-web/src/main/java/org/springframework/web/service/invoker/RequestPartArgumentResolver.java @@ -78,6 +78,7 @@ public RequestPartArgumentResolver(HttpExchangeAdapter exchangeAdapter) { @Override + @Nullable protected NamedValueInfo createNamedValueInfo(MethodParameter parameter) { RequestPart annot = parameter.getParameterAnnotation(RequestPart.class); boolean isMultiPartFile = parameter.nestedIfOptional().getNestedParameterType().equals(MultipartFile.class); diff --git a/spring-web/src/main/java/org/springframework/web/util/HierarchicalUriComponents.java b/spring-web/src/main/java/org/springframework/web/util/HierarchicalUriComponents.java index ceb8f0d69c4a..c97f84e6985a 100644 --- a/spring-web/src/main/java/org/springframework/web/util/HierarchicalUriComponents.java +++ b/spring-web/src/main/java/org/springframework/web/util/HierarchicalUriComponents.java @@ -1077,6 +1077,7 @@ public QueryUriTemplateVariables(UriTemplateVariables delegate) { } @Override + @Nullable public Object getValue(@Nullable String name) { Object value = this.delegate.getValue(name); if (ObjectUtils.isArray(value)) { diff --git a/spring-web/src/main/java/org/springframework/web/util/UriComponentsBuilder.java b/spring-web/src/main/java/org/springframework/web/util/UriComponentsBuilder.java index e6f9f8fca092..2895056499e9 100644 --- a/spring-web/src/main/java/org/springframework/web/util/UriComponentsBuilder.java +++ b/spring-web/src/main/java/org/springframework/web/util/UriComponentsBuilder.java @@ -676,7 +676,7 @@ public UriComponentsBuilder replaceQuery(@Nullable String query) { } @Override - public UriComponentsBuilder queryParam(String name, Object... values) { + public UriComponentsBuilder queryParam(String name, @Nullable Object... values) { Assert.notNull(name, "Name must not be null"); if (!ObjectUtils.isEmpty(values)) { for (Object value : values) { @@ -926,6 +926,7 @@ public void append(String path) { } @Override + @Nullable public PathComponent build() { if (this.path.length() == 0) { return null; @@ -976,6 +977,7 @@ public void append(String... pathSegments) { } @Override + @Nullable public PathComponent build() { return (this.pathSegments.isEmpty() ? null : new HierarchicalUriComponents.PathSegmentComponent(this.pathSegments)); diff --git a/spring-web/src/main/java/org/springframework/web/util/WebUtils.java b/spring-web/src/main/java/org/springframework/web/util/WebUtils.java index ed1317ed520a..25d56cf8d8cc 100644 --- a/spring-web/src/main/java/org/springframework/web/util/WebUtils.java +++ b/spring-web/src/main/java/org/springframework/web/util/WebUtils.java @@ -540,7 +540,7 @@ public static void exposeErrorRequestAttributes(HttpServletRequest request, Thro * @param name the name 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) { request.setAttribute(name, value); } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/handler/WebFluxResponseStatusExceptionHandler.java b/spring-webflux/src/main/java/org/springframework/web/reactive/handler/WebFluxResponseStatusExceptionHandler.java index d37071b13eab..3583410aa46c 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/handler/WebFluxResponseStatusExceptionHandler.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/handler/WebFluxResponseStatusExceptionHandler.java @@ -18,6 +18,7 @@ import org.springframework.core.annotation.AnnotatedElementUtils; import org.springframework.http.HttpStatusCode; +import org.springframework.lang.Nullable; import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.server.handler.ResponseStatusExceptionHandler; @@ -38,6 +39,7 @@ public class WebFluxResponseStatusExceptionHandler extends ResponseStatusExceptionHandler { @Override + @Nullable protected HttpStatusCode determineStatus(Throwable ex) { HttpStatusCode statusCode = super.determineStatus(ex); if (statusCode == null) { diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/RequestAttributeMethodArgumentResolver.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/RequestAttributeMethodArgumentResolver.java index 36200dbfae72..537e565828d6 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/RequestAttributeMethodArgumentResolver.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/RequestAttributeMethodArgumentResolver.java @@ -66,6 +66,7 @@ protected NamedValueInfo createNamedValueInfo(MethodParameter parameter) { } @Override + @Nullable protected Object resolveNamedValue(String name, MethodParameter parameter, ServerWebExchange exchange) { Object value = exchange.getAttribute(name); ReactiveAdapter toAdapter = getAdapterRegistry().getAdapter(parameter.getParameterType()); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/FrameworkServlet.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/FrameworkServlet.java index 6d48821981a4..6e666799b246 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/FrameworkServlet.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/FrameworkServlet.java @@ -1215,7 +1215,7 @@ public void preProcess(NativeWebRequest webRequest, Callable task) { } } @Override - public void postProcess(NativeWebRequest webRequest, Callable task, Object concurrentResult) { + public void postProcess(NativeWebRequest webRequest, Callable task, @Nullable Object concurrentResult) { HttpServletRequest request = webRequest.getNativeRequest(HttpServletRequest.class); if (request != null) { resetContextHolders(request, null, null); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletModelAttributeMethodProcessor.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletModelAttributeMethodProcessor.java index 5569bc8b7737..2ba95d3e9c28 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletModelAttributeMethodProcessor.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletModelAttributeMethodProcessor.java @@ -70,6 +70,7 @@ public ServletModelAttributeMethodProcessor(boolean annotationNotRequired) { * @see #createAttributeFromRequestValue */ @Override + @Nullable protected final Object createAttribute(String attributeName, MethodParameter parameter, WebDataBinderFactory binderFactory, NativeWebRequest request) throws Exception { diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/WebSocketHttpHeaders.java b/spring-websocket/src/main/java/org/springframework/web/socket/WebSocketHttpHeaders.java index 08cd92c371f7..fa4c9037b83c 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/WebSocketHttpHeaders.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/WebSocketHttpHeaders.java @@ -257,6 +257,7 @@ public boolean containsValue(Object value) { } @Override + @Nullable public List get(Object key) { return this.headers.get(key); } diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/adapter/jetty/JettyWebSocketSession.java b/spring-websocket/src/main/java/org/springframework/web/socket/adapter/jetty/JettyWebSocketSession.java index f365f717f088..cefb77f005f1 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/adapter/jetty/JettyWebSocketSession.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/adapter/jetty/JettyWebSocketSession.java @@ -114,6 +114,7 @@ public HttpHeaders getHandshakeHeaders() { } @Override + @Nullable public String getAcceptedProtocol() { checkNativeSessionInitialized(); return this.acceptedProtocol; @@ -126,6 +127,7 @@ public List getExtensions() { } @Override + @Nullable public Principal getPrincipal() { return this.user; } diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/adapter/standard/StandardWebSocketSession.java b/spring-websocket/src/main/java/org/springframework/web/socket/adapter/standard/StandardWebSocketSession.java index 5137afde36bd..ba443e6b3609 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/adapter/standard/StandardWebSocketSession.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/adapter/standard/StandardWebSocketSession.java @@ -129,6 +129,7 @@ public HttpHeaders getHandshakeHeaders() { } @Override + @Nullable public String getAcceptedProtocol() { checkNativeSessionInitialized(); return this.acceptedProtocol; @@ -141,6 +142,7 @@ public List getExtensions() { } @Override + @Nullable public Principal getPrincipal() { return this.user; } diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/adapter/standard/WebSocketToStandardExtensionAdapter.java b/spring-websocket/src/main/java/org/springframework/web/socket/adapter/standard/WebSocketToStandardExtensionAdapter.java index c3bc04b974bd..f8334d3ff349 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/adapter/standard/WebSocketToStandardExtensionAdapter.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/adapter/standard/WebSocketToStandardExtensionAdapter.java @@ -21,6 +21,7 @@ import jakarta.websocket.Extension; +import org.springframework.lang.Nullable; import org.springframework.web.socket.WebSocketExtension; /** @@ -46,6 +47,7 @@ public String getName() { return paramName; } @Override + @Nullable public String getValue() { return extension.getParameters().get(paramName); } diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/config/MessageBrokerBeanDefinitionParser.java b/spring-websocket/src/main/java/org/springframework/web/socket/config/MessageBrokerBeanDefinitionParser.java index b06c9a800386..78835e0c79c8 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/config/MessageBrokerBeanDefinitionParser.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/config/MessageBrokerBeanDefinitionParser.java @@ -133,6 +133,7 @@ class MessageBrokerBeanDefinitionParser implements BeanDefinitionParser { @Override + @Nullable public BeanDefinition parse(Element element, ParserContext context) { Object source = context.extractSource(element); CompositeComponentDefinition compDefinition = new CompositeComponentDefinition(element.getTagName(), source); diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/handler/WebSocketSessionDecorator.java b/spring-websocket/src/main/java/org/springframework/web/socket/handler/WebSocketSessionDecorator.java index 115ee5ea0c31..fb8cc8cf3400 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/handler/WebSocketSessionDecorator.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/handler/WebSocketSessionDecorator.java @@ -96,21 +96,25 @@ public Map getAttributes() { } @Override + @Nullable public Principal getPrincipal() { return this.delegate.getPrincipal(); } @Override + @Nullable public InetSocketAddress getLocalAddress() { return this.delegate.getLocalAddress(); } @Override + @Nullable public InetSocketAddress getRemoteAddress() { return this.delegate.getRemoteAddress(); } @Override + @Nullable public String getAcceptedProtocol() { return this.delegate.getAcceptedProtocol(); } diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/AbstractClientSockJsSession.java b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/AbstractClientSockJsSession.java index cc48741246b8..8f7616053559 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/AbstractClientSockJsSession.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/AbstractClientSockJsSession.java @@ -110,6 +110,7 @@ public Map getAttributes() { } @Override + @Nullable public Principal getPrincipal() { return this.request.getUser(); } diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/RestTemplateXhrTransport.java b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/RestTemplateXhrTransport.java index eb14d15f9320..da8e26f334f1 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/RestTemplateXhrTransport.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/RestTemplateXhrTransport.java @@ -207,6 +207,7 @@ public XhrReceiveExtractor(XhrClientSockJsSession sockJsSession) { } @Override + @Nullable public Object extractData(ClientHttpResponse response) throws IOException { HttpStatusCode httpStatus = response.getStatusCode(); if (httpStatus != HttpStatus.OK) { diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/WebSocketClientSockJsSession.java b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/WebSocketClientSockJsSession.java index e5ff91bc1ca2..26f97a09a7a3 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/WebSocketClientSockJsSession.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/WebSocketClientSockJsSession.java @@ -74,18 +74,21 @@ public T getNativeSession(@Nullable Class requiredType) { } @Override + @Nullable public InetSocketAddress getLocalAddress() { Assert.state(this.webSocketSession != null, "WebSocketSession not yet initialized"); return this.webSocketSession.getLocalAddress(); } @Override + @Nullable public InetSocketAddress getRemoteAddress() { Assert.state(this.webSocketSession != null, "WebSocketSession not yet initialized"); return this.webSocketSession.getRemoteAddress(); } @Override + @Nullable public String getAcceptedProtocol() { Assert.state(this.webSocketSession != null, "WebSocketSession not yet initialized"); return this.webSocketSession.getAcceptedProtocol(); diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/XhrClientSockJsSession.java b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/XhrClientSockJsSession.java index cb2012602333..2eb82afd3d06 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/XhrClientSockJsSession.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/XhrClientSockJsSession.java @@ -24,6 +24,7 @@ import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.web.socket.CloseStatus; import org.springframework.web.socket.TextMessage; @@ -96,17 +97,20 @@ public HttpHeaders getHeaders() { } @Override + @Nullable public InetSocketAddress getLocalAddress() { return null; } @Override + @Nullable public InetSocketAddress getRemoteAddress() { URI uri = getUri(); return (uri != null ? new InetSocketAddress(uri.getHost(), uri.getPort()) : null); } @Override + @Nullable public String getAcceptedProtocol() { return null; } diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/support/AbstractSockJsService.java b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/support/AbstractSockJsService.java index 4d6000371a15..c340d189bf6b 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/support/AbstractSockJsService.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/support/AbstractSockJsService.java @@ -341,6 +341,7 @@ public void setAllowedOrigins(Collection allowedOrigins) { * @since 4.1.2 */ @SuppressWarnings("ConstantConditions") + @Nullable public Collection getAllowedOrigins() { return this.corsConfiguration.getAllowedOrigins(); } @@ -363,6 +364,7 @@ public void setAllowedOriginPatterns(Collection allowedOriginPatterns) { * @since 5.3.2 */ @SuppressWarnings("ConstantConditions") + @Nullable public Collection getAllowedOriginPatterns() { return this.corsConfiguration.getAllowedOriginPatterns(); } @@ -415,8 +417,8 @@ else if (sockJsPath.equals("/info")) { } else if (sockJsPath.matches("/iframe[0-9-.a-z_]*.html")) { - if (!getAllowedOrigins().isEmpty() && !getAllowedOrigins().contains("*") || - !getAllowedOriginPatterns().isEmpty()) { + if (!CollectionUtils.isEmpty(getAllowedOrigins()) && !getAllowedOrigins().contains("*") || + !CollectionUtils.isEmpty(getAllowedOriginPatterns())) { if (requestInfo != null) { logger.debug("Iframe support is disabled when an origin check is required. " + "Ignoring transport request: " + requestInfo); @@ -424,7 +426,7 @@ else if (sockJsPath.matches("/iframe[0-9-.a-z_]*.html")) { response.setStatusCode(HttpStatus.NOT_FOUND); return; } - if (getAllowedOrigins().isEmpty()) { + if (CollectionUtils.isEmpty(getAllowedOrigins())) { response.getHeaders().add(XFRAME_OPTIONS_HEADER, "SAMEORIGIN"); } if (requestInfo != null) { diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/TransportHandlingSockJsService.java b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/TransportHandlingSockJsService.java index 2dfd9e452dbe..2a48271f60d0 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/TransportHandlingSockJsService.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/TransportHandlingSockJsService.java @@ -346,8 +346,8 @@ protected boolean validateRequest(String serverId, String sessionId, String tran return false; } - if (!getAllowedOrigins().isEmpty() && !getAllowedOrigins().contains("*") || - !getAllowedOriginPatterns().isEmpty()) { + if (!CollectionUtils.isEmpty(getAllowedOrigins()) && !getAllowedOrigins().contains("*") || + !CollectionUtils.isEmpty(getAllowedOriginPatterns())) { TransportType transportType = TransportType.fromValue(transport); if (transportType == null || !transportType.supportsOrigin()) { if (logger.isWarnEnabled()) { diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/session/WebSocketServerSockJsSession.java b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/session/WebSocketServerSockJsSession.java index ded5f410eb24..50fb16b1ca6f 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/session/WebSocketServerSockJsSession.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/session/WebSocketServerSockJsSession.java @@ -83,24 +83,28 @@ public HttpHeaders getHandshakeHeaders() { } @Override + @Nullable public Principal getPrincipal() { Assert.state(this.webSocketSession != null, "WebSocketSession not yet initialized"); return this.webSocketSession.getPrincipal(); } @Override + @Nullable public InetSocketAddress getLocalAddress() { Assert.state(this.webSocketSession != null, "WebSocketSession not yet initialized"); return this.webSocketSession.getLocalAddress(); } @Override + @Nullable public InetSocketAddress getRemoteAddress() { Assert.state(this.webSocketSession != null, "WebSocketSession not yet initialized"); return this.webSocketSession.getRemoteAddress(); } @Override + @Nullable public String getAcceptedProtocol() { Assert.state(this.webSocketSession != null, "WebSocketSession not yet initialized"); return this.webSocketSession.getAcceptedProtocol();