Skip to content

Commit b931598

Browse files
sdeleuzeasifebrahim
authored andcommitted
Upgrade nullability plugin to 0.0.4
This commit also includes related refinements of JdbcTemplate#getSingleColumnRowMapper and ObjectUtils#addObjectToArray. Closes gh-35340
1 parent fe7da9a commit b931598

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ plugins {
66
id 'com.github.bjornvester.xjc' version '1.8.2' apply false
77
id 'io.github.goooler.shadow' version '8.1.8' apply false
88
id 'me.champeau.jmh' version '0.7.2' apply false
9-
id "io.spring.nullability" version "0.0.1" apply false
9+
id 'io.spring.nullability' version '0.0.4' apply false
1010
}
1111

1212
ext {

spring-core/src/main/java/org/springframework/util/ObjectUtils.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ public static <E extends Enum<?>> E caseInsensitiveValueOf(E[] enumValues, Strin
255255
* @param obj the object to append
256256
* @return the new array (of the same component type; never {@code null})
257257
*/
258-
public static <A, O extends A> A[] addObjectToArray(A @Nullable [] array, @Nullable O obj) {
258+
public static <A, O extends A> A[] addObjectToArray(A @Nullable [] array, O obj) {
259259
return addObjectToArray(array, obj, (array != null ? array.length : 0));
260260
}
261261

@@ -268,17 +268,18 @@ public static <A, O extends A> A[] addObjectToArray(A @Nullable [] array, @Nulla
268268
* @return the new array (of the same component type; never {@code null})
269269
* @since 6.0
270270
*/
271-
public static <A, O extends A> @Nullable A[] addObjectToArray(A @Nullable [] array, @Nullable O obj, int position) {
271+
public static <A, O extends A> A[] addObjectToArray(A @Nullable [] array, O obj, int position) {
272272
Class<?> componentType = Object.class;
273273
if (array != null) {
274274
componentType = array.getClass().componentType();
275275
}
276+
// Defensive code for use cases not following the declared nullability
276277
else if (obj != null) {
277278
componentType = obj.getClass();
278279
}
279280
int newArrayLength = (array != null ? array.length + 1 : 1);
280281
@SuppressWarnings("unchecked")
281-
@Nullable A[] newArray = (A[]) Array.newInstance(componentType, newArrayLength);
282+
A[] newArray = (A[]) Array.newInstance(componentType, newArrayLength);
282283
if (array != null) {
283284
System.arraycopy(array, 0, newArray, 0, position);
284285
System.arraycopy(array, position, newArray, position + 1, array.length - position);

spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcTemplate.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1413,7 +1413,7 @@ else if (param.getResultSetExtractor() != null) {
14131413
* @return the RowMapper to use
14141414
* @see SingleColumnRowMapper
14151415
*/
1416-
protected <T> RowMapper<@Nullable T> getSingleColumnRowMapper(Class<T> requiredType) {
1416+
protected <T extends @Nullable Object> RowMapper<T> getSingleColumnRowMapper(Class<T> requiredType) {
14171417
return new SingleColumnRowMapper<>(requiredType);
14181418
}
14191419

0 commit comments

Comments
 (0)