From 5be36ce8cec5bcd45526651574760eb2b4cbaa8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Deleuze?= Date: Mon, 13 Jan 2025 20:53:46 +0100 Subject: [PATCH] Specify generic type nullness in spring-r2dbc See gh-34140 --- .../r2dbc/core/BeanPropertyRowMapper.java | 11 +++++++---- .../r2dbc/core/DataClassRowMapper.java | 7 ++++--- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/BeanPropertyRowMapper.java b/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/BeanPropertyRowMapper.java index d3b7f004781c..6e31088d1eb6 100644 --- a/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/BeanPropertyRowMapper.java +++ b/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/BeanPropertyRowMapper.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 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. @@ -125,7 +125,7 @@ public BeanPropertyRowMapper(Class mappedClass, ConversionService conversionS * Remove the specified property from the mapped properties. * @param propertyName the property name (as used by property descriptors) */ - protected void suppressProperty(String propertyName) { + protected void suppressProperty(@Nullable String propertyName) { this.mappedProperties.remove(lowerCaseName(propertyName)); this.mappedProperties.remove(underscoreName(propertyName)); } @@ -136,7 +136,10 @@ protected void suppressProperty(String propertyName) { * @param name the original name * @return the converted name */ - protected String lowerCaseName(String name) { + protected String lowerCaseName(@Nullable String name) { + if (!StringUtils.hasLength(name)) { + return ""; + } return name.toLowerCase(Locale.US); } @@ -147,7 +150,7 @@ protected String lowerCaseName(String name) { * @return the converted name * @see #lowerCaseName */ - protected String underscoreName(String name) { + protected String underscoreName(@Nullable String name) { if (!StringUtils.hasLength(name)) { return ""; } diff --git a/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/DataClassRowMapper.java b/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/DataClassRowMapper.java index c0b6af51a79c..facc258f720a 100644 --- a/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/DataClassRowMapper.java +++ b/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/DataClassRowMapper.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 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. @@ -21,6 +21,7 @@ import io.r2dbc.spi.Readable; import io.r2dbc.spi.ReadableMetadata; +import org.jspecify.annotations.Nullable; import org.springframework.beans.BeanUtils; import org.springframework.beans.TypeConverter; @@ -66,7 +67,7 @@ public class DataClassRowMapper extends BeanPropertyRowMapper { private final Constructor mappedConstructor; - private final String[] constructorParameterNames; + private final @Nullable String[] constructorParameterNames; private final TypeDescriptor[] constructorParameterTypes; @@ -98,7 +99,7 @@ public DataClassRowMapper(Class mappedClass, ConversionService conversionServ @Override protected T constructMappedInstance(Readable readable, List itemMetadatas, TypeConverter tc) { - Object[] args = new Object[this.constructorParameterNames.length]; + @Nullable Object[] args = new Object[this.constructorParameterNames.length]; for (int i = 0; i < args.length; i++) { String name = this.constructorParameterNames[i]; int index = findIndex(itemMetadatas, lowerCaseName(name));