Nullability refinements and related polishing (backported)
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2018 the original author or authors.
|
* Copyright 2002-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -18,6 +18,7 @@ package org.springframework.validation.support;
|
|||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.springframework.lang.Nullable;
|
||||||
import org.springframework.ui.ConcurrentModel;
|
import org.springframework.ui.ConcurrentModel;
|
||||||
import org.springframework.validation.BindingResult;
|
import org.springframework.validation.BindingResult;
|
||||||
|
|
||||||
@@ -36,17 +37,19 @@ import org.springframework.validation.BindingResult;
|
|||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
* @since 5.0
|
* @since 5.0
|
||||||
* @see BindingResult
|
* @see BindingResult
|
||||||
|
* @see BindingAwareModelMap
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
public class BindingAwareConcurrentModel extends ConcurrentModel {
|
public class BindingAwareConcurrentModel extends ConcurrentModel {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object put(String key, Object value) {
|
@Nullable
|
||||||
|
public Object put(String key, @Nullable Object value) {
|
||||||
removeBindingResultIfNecessary(key, value);
|
removeBindingResultIfNecessary(key, value);
|
||||||
return super.put(key, value);
|
return super.put(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void removeBindingResultIfNecessary(String key, Object value) {
|
private void removeBindingResultIfNecessary(String key, @Nullable Object value) {
|
||||||
if (!key.startsWith(BindingResult.MODEL_KEY_PREFIX)) {
|
if (!key.startsWith(BindingResult.MODEL_KEY_PREFIX)) {
|
||||||
String resultKey = BindingResult.MODEL_KEY_PREFIX + key;
|
String resultKey = BindingResult.MODEL_KEY_PREFIX + key;
|
||||||
BindingResult result = (BindingResult) get(resultKey);
|
BindingResult result = (BindingResult) get(resultKey);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2017 the original author or authors.
|
* Copyright 2002-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -18,6 +18,7 @@ package org.springframework.validation.support;
|
|||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.springframework.lang.Nullable;
|
||||||
import org.springframework.ui.ExtendedModelMap;
|
import org.springframework.ui.ExtendedModelMap;
|
||||||
import org.springframework.validation.BindingResult;
|
import org.springframework.validation.BindingResult;
|
||||||
|
|
||||||
@@ -39,7 +40,7 @@ import org.springframework.validation.BindingResult;
|
|||||||
public class BindingAwareModelMap extends ExtendedModelMap {
|
public class BindingAwareModelMap extends ExtendedModelMap {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object put(String key, Object value) {
|
public Object put(String key, @Nullable Object value) {
|
||||||
removeBindingResultIfNecessary(key, value);
|
removeBindingResultIfNecessary(key, value);
|
||||||
return super.put(key, value);
|
return super.put(key, value);
|
||||||
}
|
}
|
||||||
@@ -50,7 +51,7 @@ public class BindingAwareModelMap extends ExtendedModelMap {
|
|||||||
super.putAll(map);
|
super.putAll(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void removeBindingResultIfNecessary(Object key, Object value) {
|
private void removeBindingResultIfNecessary(Object key, @Nullable Object value) {
|
||||||
if (key instanceof String) {
|
if (key instanceof String) {
|
||||||
String attributeName = (String) key;
|
String attributeName = (String) key;
|
||||||
if (!attributeName.startsWith(BindingResult.MODEL_KEY_PREFIX)) {
|
if (!attributeName.startsWith(BindingResult.MODEL_KEY_PREFIX)) {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2020 the original author or authors.
|
* Copyright 2002-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -88,13 +88,13 @@ public abstract class ClassUtils {
|
|||||||
* Map with primitive wrapper type as key and corresponding primitive
|
* Map with primitive wrapper type as key and corresponding primitive
|
||||||
* type as value, for example: Integer.class -> int.class.
|
* type as value, for example: Integer.class -> int.class.
|
||||||
*/
|
*/
|
||||||
private static final Map<Class<?>, Class<?>> primitiveWrapperTypeMap = new IdentityHashMap<>(8);
|
private static final Map<Class<?>, Class<?>> primitiveWrapperTypeMap = new IdentityHashMap<>(9);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Map with primitive type as key and corresponding wrapper
|
* Map with primitive type as key and corresponding wrapper
|
||||||
* type as value, for example: int.class -> Integer.class.
|
* type as value, for example: int.class -> Integer.class.
|
||||||
*/
|
*/
|
||||||
private static final Map<Class<?>, Class<?>> primitiveTypeToWrapperMap = new IdentityHashMap<>(8);
|
private static final Map<Class<?>, Class<?>> primitiveTypeToWrapperMap = new IdentityHashMap<>(9);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Map with primitive type name as key and corresponding primitive
|
* Map with primitive type name as key and corresponding primitive
|
||||||
@@ -1322,7 +1322,7 @@ public abstract class ClassUtils {
|
|||||||
* Note that, despite being synthetic, bridge methods ({@link Method#isBridge()}) are considered
|
* Note that, despite being synthetic, bridge methods ({@link Method#isBridge()}) are considered
|
||||||
* as user-level methods since they are eventually pointing to a user-declared generic method.
|
* as user-level methods since they are eventually pointing to a user-declared generic method.
|
||||||
* @param method the method to check
|
* @param method the method to check
|
||||||
* @return {@code true} if the method can be considered as user-declared; [@code false} otherwise
|
* @return {@code true} if the method can be considered as user-declared; {@code false} otherwise
|
||||||
*/
|
*/
|
||||||
public static boolean isUserLevelMethod(Method method) {
|
public static boolean isUserLevelMethod(Method method) {
|
||||||
Assert.notNull(method, "Method must not be null");
|
Assert.notNull(method, "Method must not be null");
|
||||||
|
|||||||
@@ -565,7 +565,7 @@ public abstract class StringUtils {
|
|||||||
|
|
||||||
char[] chars = str.toCharArray();
|
char[] chars = str.toCharArray();
|
||||||
chars[0] = updatedChar;
|
chars[0] = updatedChar;
|
||||||
return new String(chars, 0, chars.length);
|
return new String(chars);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -120,8 +120,7 @@ public class DefaultMessageHandlerMethodFactory
|
|||||||
* the ones configured by default. This is an advanced option. For most use cases
|
* the ones configured by default. This is an advanced option. For most use cases
|
||||||
* it should be sufficient to use {@link #setCustomArgumentResolvers(java.util.List)}.
|
* it should be sufficient to use {@link #setCustomArgumentResolvers(java.util.List)}.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("ConstantConditions")
|
public void setArgumentResolvers(@Nullable List<HandlerMethodArgumentResolver> argumentResolvers) {
|
||||||
public void setArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
|
|
||||||
if (argumentResolvers == null) {
|
if (argumentResolvers == null) {
|
||||||
this.argumentResolvers.clear();
|
this.argumentResolvers.clear();
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -131,7 +131,6 @@ public class RSocketFrameTypeMessageCondition extends AbstractMessageCondition<R
|
|||||||
* @param message the current message
|
* @param message the current message
|
||||||
* @return the frame type or {@code null} if not found
|
* @return the frame type or {@code null} if not found
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("ConstantConditions")
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public static FrameType getFrameType(Message<?> message) {
|
public static FrameType getFrameType(Message<?> message) {
|
||||||
return (FrameType) message.getHeaders().get(RSocketFrameTypeMessageCondition.FRAME_TYPE_HEADER);
|
return (FrameType) message.getHeaders().get(RSocketFrameTypeMessageCondition.FRAME_TYPE_HEADER);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2016 the original author or authors.
|
* Copyright 2002-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -25,7 +25,7 @@ import java.lang.annotation.Target;
|
|||||||
import org.springframework.core.annotation.AliasFor;
|
import org.springframework.core.annotation.AliasFor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Annotation which indicates that a method parameter should be bound to an HTTP cookie.
|
* Annotation to indicate that a method parameter is bound to an HTTP cookie.
|
||||||
*
|
*
|
||||||
* <p>The method parameter may be declared as type {@link javax.servlet.http.Cookie}
|
* <p>The method parameter may be declared as type {@link javax.servlet.http.Cookie}
|
||||||
* or as cookie value type (String, int, etc.).
|
* or as cookie value type (String, int, etc.).
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2020 the original author or authors.
|
* Copyright 2002-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -59,8 +59,7 @@ public class CorsConfiguration {
|
|||||||
private static final List<String> DEFAULT_PERMIT_METHODS = Collections.unmodifiableList(
|
private static final List<String> DEFAULT_PERMIT_METHODS = Collections.unmodifiableList(
|
||||||
Arrays.asList(HttpMethod.GET.name(), HttpMethod.HEAD.name(), HttpMethod.POST.name()));
|
Arrays.asList(HttpMethod.GET.name(), HttpMethod.HEAD.name(), HttpMethod.POST.name()));
|
||||||
|
|
||||||
private static final List<String> DEFAULT_PERMIT_ALL = Collections.unmodifiableList(
|
private static final List<String> DEFAULT_PERMIT_ALL = Collections.singletonList(ALL);
|
||||||
Collections.singletonList(ALL));
|
|
||||||
|
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2019 the original author or authors.
|
* Copyright 2002-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -59,7 +59,6 @@ public class RouterFunctionMapping extends AbstractHandlerMapping implements Ini
|
|||||||
private boolean detectHandlerFunctionsInAncestorContexts = false;
|
private boolean detectHandlerFunctionsInAncestorContexts = false;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create an empty {@code RouterFunctionMapping}.
|
* Create an empty {@code RouterFunctionMapping}.
|
||||||
* <p>If this constructor is used, this mapping will detect all
|
* <p>If this constructor is used, this mapping will detect all
|
||||||
@@ -77,6 +76,7 @@ public class RouterFunctionMapping extends AbstractHandlerMapping implements Ini
|
|||||||
this.routerFunction = routerFunction;
|
this.routerFunction = routerFunction;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the router function to map to.
|
* Set the router function to map to.
|
||||||
* <p>If this property is used, no application context detection will occur.
|
* <p>If this property is used, no application context detection will occur.
|
||||||
@@ -97,6 +97,10 @@ public class RouterFunctionMapping extends AbstractHandlerMapping implements Ini
|
|||||||
return this.routerFunction;
|
return this.routerFunction;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the message body converters to use.
|
||||||
|
* <p>These converters are used to convert from and to HTTP requests and responses.
|
||||||
|
*/
|
||||||
public void setMessageConverters(List<HttpMessageConverter<?>> messageConverters) {
|
public void setMessageConverters(List<HttpMessageConverter<?>> messageConverters) {
|
||||||
this.messageConverters = messageConverters;
|
this.messageConverters = messageConverters;
|
||||||
}
|
}
|
||||||
@@ -113,6 +117,7 @@ public class RouterFunctionMapping extends AbstractHandlerMapping implements Ini
|
|||||||
this.detectHandlerFunctionsInAncestorContexts = detectHandlerFunctionsInAncestorContexts;
|
this.detectHandlerFunctionsInAncestorContexts = detectHandlerFunctionsInAncestorContexts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterPropertiesSet() throws Exception {
|
public void afterPropertiesSet() throws Exception {
|
||||||
if (this.routerFunction == null) {
|
if (this.routerFunction == null) {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2020 the original author or authors.
|
* Copyright 2002-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -359,6 +359,7 @@ public abstract class AbstractHandlerMethodMapping<T> extends AbstractHandlerMap
|
|||||||
* Look up a handler method for the given request.
|
* Look up a handler method for the given request.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
@Nullable
|
||||||
protected HandlerMethod getHandlerInternal(HttpServletRequest request) throws Exception {
|
protected HandlerMethod getHandlerInternal(HttpServletRequest request) throws Exception {
|
||||||
String lookupPath = getUrlPathHelper().getLookupPathForRequest(request);
|
String lookupPath = getUrlPathHelper().getLookupPathForRequest(request);
|
||||||
request.setAttribute(LOOKUP_PATH, lookupPath);
|
request.setAttribute(LOOKUP_PATH, lookupPath);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2020 the original author or authors.
|
* Copyright 2002-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -33,6 +33,7 @@ import org.springframework.http.HttpHeaders;
|
|||||||
import org.springframework.http.HttpMethod;
|
import org.springframework.http.HttpMethod;
|
||||||
import org.springframework.http.InvalidMediaTypeException;
|
import org.springframework.http.InvalidMediaTypeException;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.lang.Nullable;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
import org.springframework.util.MultiValueMap;
|
import org.springframework.util.MultiValueMap;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
@@ -104,6 +105,7 @@ public abstract class RequestMappingInfoHandlerMapping extends AbstractHandlerMe
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Nullable
|
||||||
protected HandlerMethod getHandlerInternal(HttpServletRequest request) throws Exception {
|
protected HandlerMethod getHandlerInternal(HttpServletRequest request) throws Exception {
|
||||||
request.removeAttribute(PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE);
|
request.removeAttribute(PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE);
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -847,12 +847,12 @@ This approach shows that the factory bean itself can be managed and configured t
|
|||||||
dependency injection (DI). See <<beans-factory-properties-detailed,Dependencies and
|
dependency injection (DI). See <<beans-factory-properties-detailed,Dependencies and
|
||||||
Configuration in Detail>>.
|
Configuration in Detail>>.
|
||||||
|
|
||||||
NOTE: In Spring documentation, "`factory bean`" refers to a bean that is configured in
|
NOTE: In Spring documentation, "factory bean" refers to a bean that is configured in the
|
||||||
the Spring container and that creates objects through an
|
Spring container and that creates objects through an
|
||||||
<<beans-factory-class-instance-factory-method,instance>> or
|
<<beans-factory-class-instance-factory-method,instance>> or
|
||||||
<<beans-factory-class-static-factory-method,static>> factory method. By contrast,
|
<<beans-factory-class-static-factory-method,static>> factory method. By contrast,
|
||||||
`FactoryBean` (notice the capitalization) refers to a Spring-specific
|
`FactoryBean` (notice the capitalization) refers to a Spring-specific
|
||||||
<<beans-factory-extension-factorybean, `FactoryBean` >> implementation class.
|
<<beans-factory-extension-factorybean, `FactoryBean`>> implementation class.
|
||||||
|
|
||||||
|
|
||||||
[[beans-factory-type-determination]]
|
[[beans-factory-type-determination]]
|
||||||
@@ -8279,7 +8279,7 @@ it resembles the following:
|
|||||||
fun userService(): Service {
|
fun userService(): Service {
|
||||||
return SimpleUserService().apply {
|
return SimpleUserService().apply {
|
||||||
// a reference to the proxied userPreferences bean
|
// a reference to the proxied userPreferences bean
|
||||||
setUserPreferences(userPreferences()
|
setUserPreferences(userPreferences())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
----
|
----
|
||||||
|
|||||||
Reference in New Issue
Block a user