Refine null-safety in more modules

This commit refines the null-safety in:
 - spring-jdbc
 - spring-r2dbc
 - spring-orm
 - spring-beans
 - spring-aop

See gh-32475
This commit is contained in:
Sébastien Deleuze
2024-03-26 09:46:34 +01:00
parent dea31dd55e
commit 1b563f8ba4
40 changed files with 69 additions and 17 deletions

View File

@@ -19,6 +19,7 @@ package org.springframework.jdbc;
import java.sql.SQLException;
import org.springframework.dao.InvalidDataAccessResourceUsageException;
import org.springframework.lang.Nullable;
/**
* Exception thrown when SQL specified is invalid. Such exceptions always have
@@ -52,6 +53,7 @@ public class BadSqlGrammarException extends InvalidDataAccessResourceUsageExcept
/**
* Return the wrapped SQLException.
*/
@Nullable
public SQLException getSQLException() {
return (SQLException) getCause();
}

View File

@@ -64,6 +64,7 @@ public class InvalidResultSetAccessException extends InvalidDataAccessResourceUs
/**
* Return the wrapped SQLException.
*/
@Nullable
public SQLException getSQLException() {
return (SQLException) getCause();
}

View File

@@ -19,6 +19,7 @@ package org.springframework.jdbc;
import java.sql.SQLWarning;
import org.springframework.dao.UncategorizedDataAccessException;
import org.springframework.lang.Nullable;
/**
* Exception thrown when we're not ignoring {@link java.sql.SQLWarning SQLWarnings}.
@@ -49,6 +50,7 @@ public class SQLWarningException extends UncategorizedDataAccessException {
* Return the underlying {@link SQLWarning}.
* @since 5.3.29
*/
@Nullable
public SQLWarning getSQLWarning() {
return (SQLWarning) getCause();
}
@@ -58,6 +60,7 @@ public class SQLWarningException extends UncategorizedDataAccessException {
* @deprecated as of 5.3.29, in favor of {@link #getSQLWarning()}
*/
@Deprecated(since = "5.3.29")
@Nullable
public SQLWarning SQLWarning() {
return getSQLWarning();
}

View File

@@ -53,6 +53,7 @@ public class UncategorizedSQLException extends UncategorizedDataAccessException
/**
* Return the underlying SQLException.
*/
@Nullable
public SQLException getSQLException() {
return (SQLException) getCause();
}

View File

@@ -907,11 +907,13 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
@Deprecated
@Override
@Nullable
public <T> T queryForObject(String sql, @Nullable Object[] args, Class<T> requiredType) throws DataAccessException {
return queryForObject(sql, args, getSingleColumnRowMapper(requiredType));
}
@Override
@Nullable
public <T> T queryForObject(String sql, Class<T> requiredType, @Nullable Object... args) throws DataAccessException {
return queryForObject(sql, args, getSingleColumnRowMapper(requiredType));
}

View File

@@ -20,6 +20,7 @@ import javax.sql.DataSource;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.dao.DataAccessException;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -34,9 +35,11 @@ import org.springframework.util.Assert;
*/
public abstract class AbstractDataFieldMaxValueIncrementer implements DataFieldMaxValueIncrementer, InitializingBean {
@Nullable
private DataSource dataSource;
/** The name of the sequence/table containing the sequence. */
@Nullable
private String incrementerName;
/** The length to which a string result should be pre-pended with zeroes. */