From 2f597011480be69d323945727041e746a9a2a56d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Deleuze?= Date: Mon, 13 Jan 2025 20:54:43 +0100 Subject: [PATCH] Specify generic type nullness in spring-webmvc See gh-34140 --- .../web/servlet/i18n/CookieLocaleResolver.java | 6 +++--- .../web/servlet/i18n/SessionLocaleResolver.java | 6 +++--- .../mvc/condition/CompositeRequestCondition.java | 7 ++++--- .../ExceptionHandlerExceptionResolver.java | 4 ++-- .../annotation/RequestMappingHandlerMapping.java | 4 ++-- .../annotation/ServletInvocableHandlerMethod.java | 4 ++-- .../web/servlet/support/BindStatus.java | 14 ++++++++------ 7 files changed, 24 insertions(+), 21 deletions(-) diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/i18n/CookieLocaleResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/i18n/CookieLocaleResolver.java index 32c3c1bab8..68486969f6 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/i18n/CookieLocaleResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/i18n/CookieLocaleResolver.java @@ -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 defaultTimeZoneFunction = request -> getDefaultTimeZone(); + private Function defaultTimeZoneFunction = request -> getDefaultTimeZone(); /** @@ -280,7 +280,7 @@ public class CookieLocaleResolver extends AbstractLocaleContextResolver { * @since 6.0 * @see #setDefaultTimeZone */ - public void setDefaultTimeZoneFunction(Function defaultTimeZoneFunction) { + public void setDefaultTimeZoneFunction(Function defaultTimeZoneFunction) { Assert.notNull(defaultTimeZoneFunction, "defaultTimeZoneFunction must not be null"); this.defaultTimeZoneFunction = defaultTimeZoneFunction; } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/i18n/SessionLocaleResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/i18n/SessionLocaleResolver.java index 61865b6845..2a3a474b86 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/i18n/SessionLocaleResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/i18n/SessionLocaleResolver.java @@ -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 defaultTimeZoneFunction = request -> getDefaultTimeZone(); + private Function 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 defaultTimeZoneFunction) { + public void setDefaultTimeZoneFunction(Function defaultTimeZoneFunction) { Assert.notNull(defaultTimeZoneFunction, "defaultTimeZoneFunction must not be null"); this.defaultTimeZoneFunction = defaultTimeZoneFunction; } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/CompositeRequestCondition.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/CompositeRequestCondition.java index 337db1c0c0..3efa288523 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/CompositeRequestCondition.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/CompositeRequestCondition.java @@ -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 objectErrors) { - String[] errorCodes = new String[objectErrors.size()]; + private static @Nullable String[] initErrorCodes(List 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") : ""); } /**