mirror of
https://github.com/spring-projects/spring-framework.git
synced 2026-09-25 16:29:28 +00:00
Specify flexible generics nullness in spring-jdbc
This commit leverages flexible generics nullness at method and type level when relevant in spring-jdbc. Due to https://github.com/uber/NullAway/issues/1075, some related `@SuppressWarnings("NullAway")` have been added. JdbcOperations Kotlin extensions have been refined accordingly. Closes gh-34911
This commit is contained in:
@@ -22,6 +22,7 @@ import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.jspecify.annotations.NonNull;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import org.springframework.dao.DataAccessException;
|
||||
@@ -115,7 +116,7 @@ public abstract class DataAccessUtils {
|
||||
* element has been found in the given Collection
|
||||
* @since 6.1
|
||||
*/
|
||||
public static <T> Optional<T> optionalResult(@Nullable Collection<T> results) throws IncorrectResultSizeDataAccessException {
|
||||
public static <T extends @Nullable Object> Optional<@NonNull T> optionalResult(@Nullable Collection<T> results) throws IncorrectResultSizeDataAccessException {
|
||||
return Optional.ofNullable(singleResult(results));
|
||||
}
|
||||
|
||||
@@ -158,7 +159,7 @@ public abstract class DataAccessUtils {
|
||||
* @throws EmptyResultDataAccessException if no element at all
|
||||
* has been found in the given Collection
|
||||
*/
|
||||
public static <T> T requiredSingleResult(@Nullable Collection<T> results) throws IncorrectResultSizeDataAccessException {
|
||||
public static <T extends @Nullable Object> @NonNull T requiredSingleResult(@Nullable Collection<T> results) throws IncorrectResultSizeDataAccessException {
|
||||
if (CollectionUtils.isEmpty(results)) {
|
||||
throw new EmptyResultDataAccessException(1);
|
||||
}
|
||||
@@ -184,7 +185,7 @@ public abstract class DataAccessUtils {
|
||||
* has been found in the given Collection
|
||||
* @since 5.0.2
|
||||
*/
|
||||
public static <T> @Nullable T nullableSingleResult(@Nullable Collection<T> results) throws IncorrectResultSizeDataAccessException {
|
||||
public static <T extends @Nullable Object> T nullableSingleResult(@Nullable Collection<T> results) throws IncorrectResultSizeDataAccessException {
|
||||
// This is identical to the requiredSingleResult implementation but differs in the
|
||||
// semantics of the incoming Collection (which we currently can't formally express)
|
||||
if (CollectionUtils.isEmpty(results)) {
|
||||
|
||||
Reference in New Issue
Block a user