Specify generic type nullness in spring-webmvc
See gh-34140
This commit is contained in:
parent
69bfb64dfd
commit
2f59701148
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -102,7 +102,7 @@ public class CookieLocaleResolver extends AbstractLocaleContextResolver {
|
|||
return (defaultLocale != null ? defaultLocale : request.getLocale());
|
||||
};
|
||||
|
||||
private Function<HttpServletRequest, TimeZone> defaultTimeZoneFunction = request -> getDefaultTimeZone();
|
||||
private Function<HttpServletRequest, @Nullable TimeZone> defaultTimeZoneFunction = request -> getDefaultTimeZone();
|
||||
|
||||
|
||||
/**
|
||||
|
@ -280,7 +280,7 @@ public class CookieLocaleResolver extends AbstractLocaleContextResolver {
|
|||
* @since 6.0
|
||||
* @see #setDefaultTimeZone
|
||||
*/
|
||||
public void setDefaultTimeZoneFunction(Function<HttpServletRequest, TimeZone> defaultTimeZoneFunction) {
|
||||
public void setDefaultTimeZoneFunction(Function<HttpServletRequest, @Nullable TimeZone> defaultTimeZoneFunction) {
|
||||
Assert.notNull(defaultTimeZoneFunction, "defaultTimeZoneFunction must not be null");
|
||||
this.defaultTimeZoneFunction = defaultTimeZoneFunction;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -93,7 +93,7 @@ public class SessionLocaleResolver extends AbstractLocaleContextResolver {
|
|||
return (defaultLocale != null ? defaultLocale : request.getLocale());
|
||||
};
|
||||
|
||||
private Function<HttpServletRequest, TimeZone> defaultTimeZoneFunction = request -> getDefaultTimeZone();
|
||||
private Function<HttpServletRequest, @Nullable TimeZone> defaultTimeZoneFunction = request -> getDefaultTimeZone();
|
||||
|
||||
/**
|
||||
* Specify the name of the corresponding attribute in the {@code HttpSession},
|
||||
|
@ -141,7 +141,7 @@ public class SessionLocaleResolver extends AbstractLocaleContextResolver {
|
|||
* @since 6.0
|
||||
* @see #setDefaultTimeZone
|
||||
*/
|
||||
public void setDefaultTimeZoneFunction(Function<HttpServletRequest, TimeZone> defaultTimeZoneFunction) {
|
||||
public void setDefaultTimeZoneFunction(Function<HttpServletRequest, @Nullable TimeZone> defaultTimeZoneFunction) {
|
||||
Assert.notNull(defaultTimeZoneFunction, "defaultTimeZoneFunction must not be null");
|
||||
this.defaultTimeZoneFunction = defaultTimeZoneFunction;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -150,10 +150,11 @@ public class CompositeRequestCondition extends AbstractRequestCondition<Composit
|
|||
}
|
||||
RequestConditionHolder[] matchingConditions = new RequestConditionHolder[getLength()];
|
||||
for (int i = 0; i < getLength(); i++) {
|
||||
matchingConditions[i] = this.requestConditions[i].getMatchingCondition(request);
|
||||
if (matchingConditions[i] == null) {
|
||||
RequestConditionHolder matchingCondition = this.requestConditions[i].getMatchingCondition(request);
|
||||
if (matchingCondition == null) {
|
||||
return null;
|
||||
}
|
||||
matchingConditions[i] = matchingCondition;
|
||||
}
|
||||
return new CompositeRequestCondition(matchingConditions);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
* Copyright 2002-2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -454,7 +454,7 @@ public class ExceptionHandlerExceptionResolver extends AbstractHandlerMethodExce
|
|||
Throwable cause = exToExpose.getCause();
|
||||
exToExpose = (cause != exToExpose ? cause : null);
|
||||
}
|
||||
Object[] arguments = new Object[exceptions.size() + 1];
|
||||
@Nullable Object[] arguments = new Object[exceptions.size() + 1];
|
||||
exceptions.toArray(arguments); // efficient arraycopy call in ArrayList
|
||||
arguments[arguments.length - 1] = handlerMethod;
|
||||
exceptionHandlerMethod.invokeAndHandle(webRequest, mavContainer, arguments);
|
||||
|
|
|
@ -331,12 +331,12 @@ public class RequestMappingHandlerMapping extends RequestMappingInfoHandlerMappi
|
|||
* Resolve placeholder values in the given array of patterns.
|
||||
* @return a new array with updated patterns
|
||||
*/
|
||||
protected String[] resolveEmbeddedValuesInPatterns(String[] patterns) {
|
||||
protected @Nullable String[] resolveEmbeddedValuesInPatterns(String[] patterns) {
|
||||
if (this.embeddedValueResolver == null) {
|
||||
return patterns;
|
||||
}
|
||||
else {
|
||||
String[] resolvedPatterns = new String[patterns.length];
|
||||
@Nullable String[] resolvedPatterns = new String[patterns.length];
|
||||
for (int i = 0; i < patterns.length; i++) {
|
||||
resolvedPatterns[i] = this.embeddedValueResolver.resolveStringValue(patterns[i]);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
* Copyright 2002-2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -112,7 +112,7 @@ public class ServletInvocableHandlerMethod extends InvocableHandlerMethod {
|
|||
* @param providedArgs "given" arguments matched by type (not resolved)
|
||||
*/
|
||||
public void invokeAndHandle(ServletWebRequest webRequest, ModelAndViewContainer mavContainer,
|
||||
Object... providedArgs) throws Exception {
|
||||
@Nullable Object... providedArgs) throws Exception {
|
||||
|
||||
Object returnValue = invokeForRequest(webRequest, mavContainer, providedArgs);
|
||||
setResponseStatus(webRequest);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -19,6 +19,7 @@ package org.springframework.web.servlet.support;
|
|||
import java.beans.PropertyEditor;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
|
@ -60,7 +61,7 @@ public class BindStatus {
|
|||
|
||||
private final @Nullable Errors errors;
|
||||
|
||||
private final String[] errorCodes;
|
||||
private final @Nullable String[] errorCodes;
|
||||
|
||||
private String @Nullable [] errorMessages;
|
||||
|
||||
|
@ -163,8 +164,8 @@ public class BindStatus {
|
|||
/**
|
||||
* Extract the error codes from the ObjectError list.
|
||||
*/
|
||||
private static String[] initErrorCodes(List<? extends ObjectError> objectErrors) {
|
||||
String[] errorCodes = new String[objectErrors.size()];
|
||||
private static @Nullable String[] initErrorCodes(List<? extends ObjectError> objectErrors) {
|
||||
@Nullable String[] errorCodes = new String[objectErrors.size()];
|
||||
for (int i = 0; i < objectErrors.size(); i++) {
|
||||
ObjectError error = objectErrors.get(i);
|
||||
errorCodes[i] = error.getCode();
|
||||
|
@ -247,7 +248,7 @@ public class BindStatus {
|
|||
* Return the error codes for the field or object, if any.
|
||||
* Returns an empty array instead of null if none.
|
||||
*/
|
||||
public String[] getErrorCodes() {
|
||||
public @Nullable String[] getErrorCodes() {
|
||||
return this.errorCodes;
|
||||
}
|
||||
|
||||
|
@ -255,7 +256,8 @@ public class BindStatus {
|
|||
* Return the first error codes for the field or object, if any.
|
||||
*/
|
||||
public String getErrorCode() {
|
||||
return (this.errorCodes.length > 0 ? this.errorCodes[0] : "");
|
||||
return (this.errorCodes.length > 0 ? Objects.requireNonNull(this.errorCodes[0],
|
||||
"Error code must not be null") : "");
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue