Specify generic type nullness in spring-r2dbc

See gh-34140
This commit is contained in:
Sébastien Deleuze 2025-01-13 20:53:46 +01:00
parent 2f8ff7eb41
commit 5be36ce8ce
2 changed files with 11 additions and 7 deletions

View File

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -125,7 +125,7 @@ public class BeanPropertyRowMapper<T> implements Function<Readable, T> {
* Remove the specified property from the mapped properties. * Remove the specified property from the mapped properties.
* @param propertyName the property name (as used by property descriptors) * @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(lowerCaseName(propertyName));
this.mappedProperties.remove(underscoreName(propertyName)); this.mappedProperties.remove(underscoreName(propertyName));
} }
@ -136,7 +136,10 @@ public class BeanPropertyRowMapper<T> implements Function<Readable, T> {
* @param name the original name * @param name the original name
* @return the converted 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); return name.toLowerCase(Locale.US);
} }
@ -147,7 +150,7 @@ public class BeanPropertyRowMapper<T> implements Function<Readable, T> {
* @return the converted name * @return the converted name
* @see #lowerCaseName * @see #lowerCaseName
*/ */
protected String underscoreName(String name) { protected String underscoreName(@Nullable String name) {
if (!StringUtils.hasLength(name)) { if (!StringUtils.hasLength(name)) {
return ""; return "";
} }

View File

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -21,6 +21,7 @@ import java.util.List;
import io.r2dbc.spi.Readable; import io.r2dbc.spi.Readable;
import io.r2dbc.spi.ReadableMetadata; import io.r2dbc.spi.ReadableMetadata;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.TypeConverter; import org.springframework.beans.TypeConverter;
@ -66,7 +67,7 @@ public class DataClassRowMapper<T> extends BeanPropertyRowMapper<T> {
private final Constructor<T> mappedConstructor; private final Constructor<T> mappedConstructor;
private final String[] constructorParameterNames; private final @Nullable String[] constructorParameterNames;
private final TypeDescriptor[] constructorParameterTypes; private final TypeDescriptor[] constructorParameterTypes;
@ -98,7 +99,7 @@ public class DataClassRowMapper<T> extends BeanPropertyRowMapper<T> {
@Override @Override
protected T constructMappedInstance(Readable readable, List<? extends ReadableMetadata> itemMetadatas, TypeConverter tc) { protected T constructMappedInstance(Readable readable, List<? extends ReadableMetadata> 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++) { for (int i = 0; i < args.length; i++) {
String name = this.constructorParameterNames[i]; String name = this.constructorParameterNames[i];
int index = findIndex(itemMetadatas, lowerCaseName(name)); int index = findIndex(itemMetadatas, lowerCaseName(name));