Skip to content

Commit 23f396a

Browse files
committed
Nullability refinements
1 parent 090e394 commit 23f396a

File tree

6 files changed

+28
-12
lines changed

6 files changed

+28
-12
lines changed

spring-context/src/main/java/org/springframework/validation/support/BindingAwareConcurrentModel.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,6 +18,7 @@
1818

1919
import java.util.Map;
2020

21+
import org.springframework.lang.Nullable;
2122
import org.springframework.ui.ConcurrentModel;
2223
import org.springframework.validation.BindingResult;
2324

@@ -36,17 +37,19 @@
3637
* @author Rossen Stoyanchev
3738
* @since 5.0
3839
* @see BindingResult
40+
* @see BindingAwareModelMap
3941
*/
4042
@SuppressWarnings("serial")
4143
public class BindingAwareConcurrentModel extends ConcurrentModel {
4244

4345
@Override
44-
public Object put(String key, Object value) {
46+
@Nullable
47+
public Object put(String key, @Nullable Object value) {
4548
removeBindingResultIfNecessary(key, value);
4649
return super.put(key, value);
4750
}
4851

49-
private void removeBindingResultIfNecessary(String key, Object value) {
52+
private void removeBindingResultIfNecessary(String key, @Nullable Object value) {
5053
if (!key.startsWith(BindingResult.MODEL_KEY_PREFIX)) {
5154
String resultKey = BindingResult.MODEL_KEY_PREFIX + key;
5255
BindingResult result = (BindingResult) get(resultKey);

spring-context/src/main/java/org/springframework/validation/support/BindingAwareModelMap.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,6 +18,7 @@
1818

1919
import java.util.Map;
2020

21+
import org.springframework.lang.Nullable;
2122
import org.springframework.ui.ExtendedModelMap;
2223
import org.springframework.validation.BindingResult;
2324

@@ -39,7 +40,7 @@
3940
public class BindingAwareModelMap extends ExtendedModelMap {
4041

4142
@Override
42-
public Object put(String key, Object value) {
43+
public Object put(String key, @Nullable Object value) {
4344
removeBindingResultIfNecessary(key, value);
4445
return super.put(key, value);
4546
}
@@ -50,7 +51,7 @@ public void putAll(Map<? extends String, ?> map) {
5051
super.putAll(map);
5152
}
5253

53-
private void removeBindingResultIfNecessary(Object key, Object value) {
54+
private void removeBindingResultIfNecessary(Object key, @Nullable Object value) {
5455
if (key instanceof String) {
5556
String attributeName = (String) key;
5657
if (!attributeName.startsWith(BindingResult.MODEL_KEY_PREFIX)) {

spring-webmvc/src/main/java/org/springframework/web/servlet/function/support/RouterFunctionMapping.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ public class RouterFunctionMapping extends AbstractHandlerMapping implements Ini
7373
private boolean detectHandlerFunctionsInAncestorContexts = false;
7474

7575

76-
7776
/**
7877
* Create an empty {@code RouterFunctionMapping}.
7978
* <p>If this constructor is used, this mapping will detect all
@@ -91,6 +90,7 @@ public RouterFunctionMapping(RouterFunction<?> routerFunction) {
9190
this.routerFunction = routerFunction;
9291
}
9392

93+
9494
/**
9595
* Set the router function to map to.
9696
* <p>If this property is used, no application context detection will occur.
@@ -111,6 +111,10 @@ public RouterFunction<?> getRouterFunction() {
111111
return this.routerFunction;
112112
}
113113

114+
/**
115+
* Set the message body converters to use.
116+
* <p>These converters are used to convert from and to HTTP requests and responses.
117+
*/
114118
public void setMessageConverters(List<HttpMessageConverter<?>> messageConverters) {
115119
this.messageConverters = messageConverters;
116120
}
@@ -127,6 +131,7 @@ public void setDetectHandlerFunctionsInAncestorContexts(boolean detectHandlerFun
127131
this.detectHandlerFunctionsInAncestorContexts = detectHandlerFunctionsInAncestorContexts;
128132
}
129133

134+
130135
@Override
131136
public void afterPropertiesSet() throws Exception {
132137
if (this.routerFunction == null) {
@@ -204,8 +209,9 @@ private void initMessageConverters() {
204209
this.messageConverters = messageConverters;
205210
}
206211

207-
@Nullable
212+
208213
@Override
214+
@Nullable
209215
protected Object getHandlerInternal(HttpServletRequest servletRequest) throws Exception {
210216
if (this.routerFunction != null) {
211217
ServerRequest request = ServerRequest.create(servletRequest, this.messageConverters);
@@ -219,8 +225,10 @@ protected Object getHandlerInternal(HttpServletRequest servletRequest) throws Ex
219225
}
220226

221227
private void setAttributes(HttpServletRequest servletRequest, ServerRequest request,
222-
HandlerFunction<?> handlerFunction) {
223-
PathPattern matchingPattern = (PathPattern) servletRequest.getAttribute(RouterFunctions.MATCHING_PATTERN_ATTRIBUTE);
228+
@Nullable HandlerFunction<?> handlerFunction) {
229+
230+
PathPattern matchingPattern =
231+
(PathPattern) servletRequest.getAttribute(RouterFunctions.MATCHING_PATTERN_ATTRIBUTE);
224232
if (matchingPattern != null) {
225233
servletRequest.removeAttribute(RouterFunctions.MATCHING_PATTERN_ATTRIBUTE);
226234
servletRequest.setAttribute(BEST_MATCHING_PATTERN_ATTRIBUTE, matchingPattern.getPatternString());

spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMethodMapping.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@ protected void handlerMethodsInitialized(Map<T, HandlerMethod> handlerMethods) {
369369
* Look up a handler method for the given request.
370370
*/
371371
@Override
372+
@Nullable
372373
protected HandlerMethod getHandlerInternal(HttpServletRequest request) throws Exception {
373374
String lookupPath = initLookupPath(request);
374375
this.mappingRegistry.acquireReadLock();

spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/RequestMappingInfoHandlerMapping.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import org.springframework.http.InvalidMediaTypeException;
3535
import org.springframework.http.MediaType;
3636
import org.springframework.http.server.PathContainer;
37+
import org.springframework.lang.Nullable;
3738
import org.springframework.util.Assert;
3839
import org.springframework.util.CollectionUtils;
3940
import org.springframework.util.MultiValueMap;
@@ -117,6 +118,7 @@ protected Comparator<RequestMappingInfo> getMappingComparator(final HttpServletR
117118
}
118119

119120
@Override
121+
@Nullable
120122
protected HandlerMethod getHandlerInternal(HttpServletRequest request) throws Exception {
121123
request.removeAttribute(PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE);
122124
try {

spring-websocket/src/main/java/org/springframework/web/socket/server/support/WebSocketHandlerMapping.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,12 @@ public boolean isRunning() {
9797
return this.running;
9898
}
9999

100-
@Nullable
100+
101101
@Override
102+
@Nullable
102103
protected Object getHandlerInternal(HttpServletRequest request) throws Exception {
103104
Object handler = super.getHandlerInternal(request);
104-
return matchWebSocketUpgrade(handler, request) ? handler : null;
105+
return (matchWebSocketUpgrade(handler, request) ? handler : null);
105106
}
106107

107108
private boolean matchWebSocketUpgrade(@Nullable Object handler, HttpServletRequest request) {

0 commit comments

Comments
 (0)