From 7a2a167f34385902c081d58be00794d5d9e6e325 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Deleuze?= Date: Mon, 18 Aug 2025 15:45:19 +0200 Subject: [PATCH] Upgrade nullability plugin to 0.0.4 This commit also includes related refinements of JdbcTemplate#getSingleColumnRowMapper and ObjectUtils#addObjectToArray. Closes gh-35340 --- build.gradle | 2 +- .../main/java/org/springframework/util/ObjectUtils.java | 7 ++++--- .../java/org/springframework/jdbc/core/JdbcTemplate.java | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/build.gradle b/build.gradle index 01b6cfcd4c4..d0dce05f0fa 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ plugins { id 'com.github.bjornvester.xjc' version '1.8.2' apply false id 'io.github.goooler.shadow' version '8.1.8' apply false id 'me.champeau.jmh' version '0.7.2' apply false - id "io.spring.nullability" version "0.0.1" apply false + id 'io.spring.nullability' version '0.0.4' apply false } ext { diff --git a/spring-core/src/main/java/org/springframework/util/ObjectUtils.java b/spring-core/src/main/java/org/springframework/util/ObjectUtils.java index 98fedfd795b..c32075563ea 100644 --- a/spring-core/src/main/java/org/springframework/util/ObjectUtils.java +++ b/spring-core/src/main/java/org/springframework/util/ObjectUtils.java @@ -255,7 +255,7 @@ public abstract class ObjectUtils { * @param obj the object to append * @return the new array (of the same component type; never {@code null}) */ - public static A[] addObjectToArray(A @Nullable [] array, @Nullable O obj) { + public static A[] addObjectToArray(A @Nullable [] array, O obj) { return addObjectToArray(array, obj, (array != null ? array.length : 0)); } @@ -268,17 +268,18 @@ public abstract class ObjectUtils { * @return the new array (of the same component type; never {@code null}) * @since 6.0 */ - public static @Nullable A[] addObjectToArray(A @Nullable [] array, @Nullable O obj, int position) { + public static A[] addObjectToArray(A @Nullable [] array, O obj, int position) { Class componentType = Object.class; if (array != null) { componentType = array.getClass().componentType(); } + // Defensive code for use cases not following the declared nullability else if (obj != null) { componentType = obj.getClass(); } int newArrayLength = (array != null ? array.length + 1 : 1); @SuppressWarnings("unchecked") - @Nullable A[] newArray = (A[]) Array.newInstance(componentType, newArrayLength); + A[] newArray = (A[]) Array.newInstance(componentType, newArrayLength); if (array != null) { System.arraycopy(array, 0, newArray, 0, position); System.arraycopy(array, position, newArray, position + 1, array.length - position); diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcTemplate.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcTemplate.java index 734b217ab7c..096d397cd37 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcTemplate.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcTemplate.java @@ -1413,7 +1413,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { * @return the RowMapper to use * @see SingleColumnRowMapper */ - protected RowMapper<@Nullable T> getSingleColumnRowMapper(Class requiredType) { + protected RowMapper getSingleColumnRowMapper(Class requiredType) { return new SingleColumnRowMapper<>(requiredType); }