Skip to content

Commit 67fccc3

Browse files
committed
Nullability refinements and related polishing (backported)
1 parent 70e6606 commit 67fccc3

File tree

12 files changed

+36
-27
lines changed

12 files changed

+36
-27
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-core/src/main/java/org/springframework/util/ClassUtils.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 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.
@@ -88,13 +88,13 @@ public abstract class ClassUtils {
8888
* Map with primitive wrapper type as key and corresponding primitive
8989
* type as value, for example: Integer.class -> int.class.
9090
*/
91-
private static final Map<Class<?>, Class<?>> primitiveWrapperTypeMap = new IdentityHashMap<>(8);
91+
private static final Map<Class<?>, Class<?>> primitiveWrapperTypeMap = new IdentityHashMap<>(9);
9292

9393
/**
9494
* Map with primitive type as key and corresponding wrapper
9595
* type as value, for example: int.class -> Integer.class.
9696
*/
97-
private static final Map<Class<?>, Class<?>> primitiveTypeToWrapperMap = new IdentityHashMap<>(8);
97+
private static final Map<Class<?>, Class<?>> primitiveTypeToWrapperMap = new IdentityHashMap<>(9);
9898

9999
/**
100100
* Map with primitive type name as key and corresponding primitive
@@ -1322,7 +1322,7 @@ public static Method getInterfaceMethodIfPossible(Method method) {
13221322
* Note that, despite being synthetic, bridge methods ({@link Method#isBridge()}) are considered
13231323
* as user-level methods since they are eventually pointing to a user-declared generic method.
13241324
* @param method the method to check
1325-
* @return {@code true} if the method can be considered as user-declared; [@code false} otherwise
1325+
* @return {@code true} if the method can be considered as user-declared; {@code false} otherwise
13261326
*/
13271327
public static boolean isUserLevelMethod(Method method) {
13281328
Assert.notNull(method, "Method must not be null");

spring-core/src/main/java/org/springframework/util/StringUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ private static String changeFirstCharacterCase(String str, boolean capitalize) {
565565

566566
char[] chars = str.toCharArray();
567567
chars[0] = updatedChar;
568-
return new String(chars, 0, chars.length);
568+
return new String(chars);
569569
}
570570

571571
/**

spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/support/DefaultMessageHandlerMethodFactory.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,7 @@ public void setCustomArgumentResolvers(List<HandlerMethodArgumentResolver> custo
120120
* the ones configured by default. This is an advanced option. For most use cases
121121
* it should be sufficient to use {@link #setCustomArgumentResolvers(java.util.List)}.
122122
*/
123-
@SuppressWarnings("ConstantConditions")
124-
public void setArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
123+
public void setArgumentResolvers(@Nullable List<HandlerMethodArgumentResolver> argumentResolvers) {
125124
if (argumentResolvers == null) {
126125
this.argumentResolvers.clear();
127126
return;

spring-messaging/src/main/java/org/springframework/messaging/rsocket/annotation/support/RSocketFrameTypeMessageCondition.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ protected String getToStringInfix() {
131131
* @param message the current message
132132
* @return the frame type or {@code null} if not found
133133
*/
134-
@SuppressWarnings("ConstantConditions")
135134
@Nullable
136135
public static FrameType getFrameType(Message<?> message) {
137136
return (FrameType) message.getHeaders().get(RSocketFrameTypeMessageCondition.FRAME_TYPE_HEADER);

spring-web/src/main/java/org/springframework/web/bind/annotation/CookieValue.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 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.
@@ -25,7 +25,7 @@
2525
import org.springframework.core.annotation.AliasFor;
2626

2727
/**
28-
* Annotation which indicates that a method parameter should be bound to an HTTP cookie.
28+
* Annotation to indicate that a method parameter is bound to an HTTP cookie.
2929
*
3030
* <p>The method parameter may be declared as type {@link javax.servlet.http.Cookie}
3131
* or as cookie value type (String, int, etc.).

spring-web/src/main/java/org/springframework/web/cors/CorsConfiguration.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 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.
@@ -59,8 +59,7 @@ public class CorsConfiguration {
5959
private static final List<String> DEFAULT_PERMIT_METHODS = Collections.unmodifiableList(
6060
Arrays.asList(HttpMethod.GET.name(), HttpMethod.HEAD.name(), HttpMethod.POST.name()));
6161

62-
private static final List<String> DEFAULT_PERMIT_ALL = Collections.unmodifiableList(
63-
Collections.singletonList(ALL));
62+
private static final List<String> DEFAULT_PERMIT_ALL = Collections.singletonList(ALL);
6463

6564

6665
@Nullable

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 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.
@@ -59,7 +59,6 @@ public class RouterFunctionMapping extends AbstractHandlerMapping implements Ini
5959
private boolean detectHandlerFunctionsInAncestorContexts = false;
6060

6161

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

79+
8080
/**
8181
* Set the router function to map to.
8282
* <p>If this property is used, no application context detection will occur.
@@ -97,6 +97,10 @@ public RouterFunction<?> getRouterFunction() {
9797
return this.routerFunction;
9898
}
9999

100+
/**
101+
* Set the message body converters to use.
102+
* <p>These converters are used to convert from and to HTTP requests and responses.
103+
*/
100104
public void setMessageConverters(List<HttpMessageConverter<?>> messageConverters) {
101105
this.messageConverters = messageConverters;
102106
}
@@ -113,6 +117,7 @@ public void setDetectHandlerFunctionsInAncestorContexts(boolean detectHandlerFun
113117
this.detectHandlerFunctionsInAncestorContexts = detectHandlerFunctionsInAncestorContexts;
114118
}
115119

120+
116121
@Override
117122
public void afterPropertiesSet() throws Exception {
118123
if (this.routerFunction == null) {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 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.
@@ -359,6 +359,7 @@ protected void handlerMethodsInitialized(Map<T, HandlerMethod> handlerMethods) {
359359
* Look up a handler method for the given request.
360360
*/
361361
@Override
362+
@Nullable
362363
protected HandlerMethod getHandlerInternal(HttpServletRequest request) throws Exception {
363364
String lookupPath = getUrlPathHelper().getLookupPathForRequest(request);
364365
request.setAttribute(LOOKUP_PATH, lookupPath);

0 commit comments

Comments
 (0)