Upgrade nullability plugin to 0.0.4

This commit also includes related refinements of
JdbcTemplate#getSingleColumnRowMapper and
ObjectUtils#addObjectToArray.

Closes gh-35340
This commit is contained in:
Sébastien Deleuze 2025-08-18 15:45:19 +02:00
parent 5d325ca0fc
commit 7a2a167f34
3 changed files with 6 additions and 5 deletions

View File

@ -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 {

View File

@ -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, O extends A> A[] addObjectToArray(A @Nullable [] array, @Nullable O obj) {
public static <A, O extends A> 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 <A, O extends A> @Nullable A[] addObjectToArray(A @Nullable [] array, @Nullable O obj, int position) {
public static <A, O extends A> 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);

View File

@ -1413,7 +1413,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
* @return the RowMapper to use
* @see SingleColumnRowMapper
*/
protected <T> RowMapper<@Nullable T> getSingleColumnRowMapper(Class<T> requiredType) {
protected <T extends @Nullable Object> RowMapper<T> getSingleColumnRowMapper(Class<T> requiredType) {
return new SingleColumnRowMapper<>(requiredType);
}