Skip to content

Commit a63ebe7

Browse files
committed
Refine null-safety in spring-web and spring-websocket
See gh-32475
1 parent c4b6150 commit a63ebe7

File tree

59 files changed

+106
-23
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+106
-23
lines changed

spring-web/src/main/java/org/springframework/web/DefaultErrorResponseBuilder.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ public String getDetailMessageCode() {
211211
}
212212

213213
@Override
214+
@Nullable
214215
public Object[] getDetailMessageArguments() {
215216
return this.detailMessageArguments;
216217
}

spring-web/src/main/java/org/springframework/web/ErrorResponseException.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ public String getDetailMessageCode() {
165165
}
166166

167167
@Override
168+
@Nullable
168169
public Object[] getDetailMessageArguments() {
169170
return this.messageDetailArguments;
170171
}

spring-web/src/main/java/org/springframework/web/HttpMediaTypeException.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ protected HttpMediaTypeException(String message, List<MediaType> supportedMediaT
7373
* resolving the problem "detail" through a {@code MessageSource}
7474
* @since 6.0
7575
*/
76-
protected HttpMediaTypeException(String message, List<MediaType> supportedMediaTypes,
76+
protected HttpMediaTypeException(@Nullable String message, List<MediaType> supportedMediaTypes,
7777
@Nullable String messageDetailCode, @Nullable Object[] messageDetailArguments) {
7878

7979
super(message);
@@ -102,6 +102,7 @@ public String getDetailMessageCode() {
102102
}
103103

104104
@Override
105+
@Nullable
105106
public Object[] getDetailMessageArguments() {
106107
return this.messageDetailArguments;
107108
}

spring-web/src/main/java/org/springframework/web/HttpMediaTypeNotSupportedException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public HttpMediaTypeNotSupportedException(String message) {
6363
* @param mediaTypes list of supported media types
6464
* @since 6.0.5
6565
*/
66-
public HttpMediaTypeNotSupportedException(String message, List<MediaType> mediaTypes) {
66+
public HttpMediaTypeNotSupportedException(@Nullable String message, List<MediaType> mediaTypes) {
6767
super(message, mediaTypes, PARSE_ERROR_DETAIL_CODE, null);
6868
this.contentType = null;
6969
this.httpMethod = null;

spring-web/src/main/java/org/springframework/web/accept/ServletPathExtensionContentNegotiationStrategy.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ protected MediaType handleNoMatch(NativeWebRequest webRequest, String extension)
9999
* @since 4.3
100100
*/
101101
@Override
102+
@Nullable
102103
public MediaType getMediaTypeForResource(Resource resource) {
103104
MediaType mediaType = null;
104105
String mimeType = this.servletContext.getMimeType(resource.getFilename());

spring-web/src/main/java/org/springframework/web/bind/ServletRequestBindingException.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public class ServletRequestBindingException extends ServletException implements
5050
* Constructor with a message only.
5151
* @param msg the detail message
5252
*/
53-
public ServletRequestBindingException(String msg) {
53+
public ServletRequestBindingException(@Nullable String msg) {
5454
this(msg, null, null);
5555
}
5656

@@ -59,7 +59,7 @@ public ServletRequestBindingException(String msg) {
5959
* @param msg the detail message
6060
* @param cause the root cause
6161
*/
62-
public ServletRequestBindingException(String msg, Throwable cause) {
62+
public ServletRequestBindingException(@Nullable String msg, @Nullable Throwable cause) {
6363
this(msg, cause, null, null);
6464
}
6565

@@ -73,7 +73,7 @@ public ServletRequestBindingException(String msg, Throwable cause) {
7373
* @since 6.0
7474
*/
7575
protected ServletRequestBindingException(
76-
String msg, @Nullable String messageDetailCode, @Nullable Object[] messageDetailArguments) {
76+
@Nullable String msg, @Nullable String messageDetailCode, @Nullable Object[] messageDetailArguments) {
7777

7878
this(msg, null, messageDetailCode, messageDetailArguments);
7979
}
@@ -88,7 +88,7 @@ protected ServletRequestBindingException(
8888
* resolving the problem "detail" through a {@code MessageSource}
8989
* @since 6.0
9090
*/
91-
protected ServletRequestBindingException(String msg, @Nullable Throwable cause,
91+
protected ServletRequestBindingException(@Nullable String msg, @Nullable Throwable cause,
9292
@Nullable String messageDetailCode, @Nullable Object[] messageDetailArguments) {
9393

9494
super(msg, cause);
@@ -118,6 +118,7 @@ public String getDetailMessageCode() {
118118
}
119119

120120
@Override
121+
@Nullable
121122
public Object[] getDetailMessageArguments() {
122123
return this.messageDetailArguments;
123124
}

spring-web/src/main/java/org/springframework/web/bind/support/BindParamNameResolver.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.springframework.web.bind.support;
1818

1919
import org.springframework.core.MethodParameter;
20+
import org.springframework.lang.Nullable;
2021
import org.springframework.util.StringUtils;
2122
import org.springframework.validation.DataBinder;
2223
import org.springframework.web.bind.annotation.BindParam;
@@ -32,6 +33,7 @@
3233
public final class BindParamNameResolver implements DataBinder.NameResolver {
3334

3435
@Override
36+
@Nullable
3537
public String resolveName(MethodParameter parameter) {
3638
BindParam bindParam = parameter.getParameterAnnotation(BindParam.class);
3739
if (bindParam != null) {

spring-web/src/main/java/org/springframework/web/bind/support/WebExchangeDataBinder.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ protected static void addBindValue(Map<String, Object> params, String key, List<
162162
private record MapValueResolver(Map<String, Object> map) implements ValueResolver {
163163

164164
@Override
165+
@Nullable
165166
public Object resolveValue(String name, Class<?> type) {
166167
return this.map.get(name);
167168
}

spring-web/src/main/java/org/springframework/web/client/HttpMessageConverterExtractor.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ public HttpMessageConverterExtractor(Type responseType, List<HttpMessageConverte
8484

8585

8686
@Override
87+
@Nullable
8788
@SuppressWarnings({"rawtypes", "unchecked", "resource"})
8889
public T extractData(ClientHttpResponse response) throws IOException {
8990
IntrospectingClientHttpResponse responseWrapper = new IntrospectingClientHttpResponse(response);

spring-web/src/main/java/org/springframework/web/client/ResourceAccessException.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
import java.io.IOException;
2020

21+
import org.springframework.lang.Nullable;
22+
2123
/**
2224
* Exception thrown when an I/O error occurs.
2325
*
@@ -42,7 +44,7 @@ public ResourceAccessException(String msg) {
4244
* @param msg the message
4345
* @param ex the {@code IOException}
4446
*/
45-
public ResourceAccessException(String msg, IOException ex) {
47+
public ResourceAccessException(String msg, @Nullable IOException ex) {
4648
super(msg, ex);
4749
}
4850

0 commit comments

Comments
 (0)