Perform NullAway build-time checks in more modules

This commit enables null-safety build-time checks 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:55:41 +01:00
parent 3b4f8dbb8e
commit 5b660da52d
46 changed files with 78 additions and 12 deletions

View File

@@ -46,6 +46,7 @@ public class ArgumentTypePreparedStatementSetter implements PreparedStatementSet
* @param args the arguments to set
* @param argTypes the corresponding SQL types of the arguments
*/
@SuppressWarnings("NullAway")
public ArgumentTypePreparedStatementSetter(@Nullable Object[] args, @Nullable int[] argTypes) {
if ((args != null && argTypes == null) || (args == null && argTypes != null) ||
(args != null && args.length != argTypes.length)) {

View File

@@ -26,6 +26,7 @@ import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.SqlParameter;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import org.springframework.lang.Nullable;
/**
* A SimpleJdbcCall is a multithreaded, reusable object representing a call
@@ -148,36 +149,42 @@ public class SimpleJdbcCall extends AbstractJdbcCall implements SimpleJdbcCallOp
}
@Override
@Nullable
@SuppressWarnings("unchecked")
public <T> T executeFunction(Class<T> returnType, Object... args) {
return (T) doExecute(args).get(getScalarOutParameterName());
}
@Override
@Nullable
@SuppressWarnings("unchecked")
public <T> T executeFunction(Class<T> returnType, Map<String, ?> args) {
return (T) doExecute(args).get(getScalarOutParameterName());
}
@Override
@Nullable
@SuppressWarnings("unchecked")
public <T> T executeFunction(Class<T> returnType, SqlParameterSource args) {
return (T) doExecute(args).get(getScalarOutParameterName());
}
@Override
@Nullable
@SuppressWarnings("unchecked")
public <T> T executeObject(Class<T> returnType, Object... args) {
return (T) doExecute(args).get(getScalarOutParameterName());
}
@Override
@Nullable
@SuppressWarnings("unchecked")
public <T> T executeObject(Class<T> returnType, Map<String, ?> args) {
return (T) doExecute(args).get(getScalarOutParameterName());
}
@Override
@Nullable
@SuppressWarnings("unchecked")
public <T> T executeObject(Class<T> returnType, SqlParameterSource args) {
return (T) doExecute(args).get(getScalarOutParameterName());

View File

@@ -21,6 +21,7 @@ import java.util.Map;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.SqlParameter;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import org.springframework.lang.Nullable;
/**
* Interface specifying the API for a Simple JDBC Call implemented by {@link SimpleJdbcCall}.
@@ -117,6 +118,7 @@ public interface SimpleJdbcCallOperations {
* Parameter values must be provided in the same order as the parameters are defined
* for the stored procedure.
*/
@Nullable
<T> T executeFunction(Class<T> returnType, Object... args);
/**
@@ -125,6 +127,7 @@ public interface SimpleJdbcCallOperations {
* @param returnType the type of the value to return
* @param args a Map containing the parameter values to be used in the call
*/
@Nullable
<T> T executeFunction(Class<T> returnType, Map<String, ?> args);
/**
@@ -133,6 +136,7 @@ public interface SimpleJdbcCallOperations {
* @param returnType the type of the value to return
* @param args the MapSqlParameterSource containing the parameter values to be used in the call
*/
@Nullable
<T> T executeFunction(Class<T> returnType, SqlParameterSource args);
/**
@@ -144,6 +148,7 @@ public interface SimpleJdbcCallOperations {
* Parameter values must be provided in the same order as the parameters are defined for
* the stored procedure.
*/
@Nullable
<T> T executeObject(Class<T> returnType, Object... args);
/**
@@ -153,6 +158,7 @@ public interface SimpleJdbcCallOperations {
* @param returnType the type of the value to return
* @param args a Map containing the parameter values to be used in the call
*/
@Nullable
<T> T executeObject(Class<T> returnType, Map<String, ?> args);
/**
@@ -162,6 +168,7 @@ public interface SimpleJdbcCallOperations {
* @param returnType the type of the value to return
* @param args the MapSqlParameterSource containing the parameter values to be used in the call
*/
@Nullable
<T> T executeObject(Class<T> returnType, SqlParameterSource args);
/**

View File

@@ -182,6 +182,7 @@ public class SingleConnectionDataSource extends DriverManagerDataSource
@Override
@SuppressWarnings("NullAway")
public Connection getConnection() throws SQLException {
this.connectionLock.lock();
try {

View File

@@ -162,6 +162,7 @@ public class EmbeddedDatabaseFactory {
* Factory method that returns the {@linkplain EmbeddedDatabase embedded database}
* instance, which is also a {@link DataSource}.
*/
@SuppressWarnings("NullAway")
public EmbeddedDatabase getDatabase() {
if (this.dataSource == null) {
initDatabase();

View File

@@ -134,6 +134,7 @@ public abstract class AbstractRoutingDataSource extends AbstractDataSource imple
* @see #getResolvedDataSources()
* @see #getResolvedDefaultDataSource()
*/
@SuppressWarnings("NullAway")
public void initialize() {
if (this.targetDataSources == null) {
throw new IllegalArgumentException("Property 'targetDataSources' is required");

View File

@@ -43,6 +43,7 @@ public abstract class AbstractColumnMaxValueIncrementer extends AbstractDataFiel
* @see #setIncrementerName
* @see #setColumnName
*/
@SuppressWarnings("NullAway")
public AbstractColumnMaxValueIncrementer() {
}

View File

@@ -77,6 +77,7 @@ public abstract class AbstractDataFieldMaxValueIncrementer implements DataFieldM
/**
* Return the data source to retrieve the value from.
*/
@SuppressWarnings("NullAway")
public DataSource getDataSource() {
return this.dataSource;
}
@@ -91,6 +92,7 @@ public abstract class AbstractDataFieldMaxValueIncrementer implements DataFieldM
/**
* Return the name of the sequence/table.
*/
@SuppressWarnings("NullAway")
public String getIncrementerName() {
return this.incrementerName;
}

View File

@@ -53,9 +53,11 @@ public abstract class AbstractIdentityColumnMaxValueIncrementer extends Abstract
* @see #setIncrementerName
* @see #setColumnName
*/
@SuppressWarnings("NullAway")
public AbstractIdentityColumnMaxValueIncrementer() {
}
@SuppressWarnings("NullAway")
public AbstractIdentityColumnMaxValueIncrementer(DataSource dataSource, String incrementerName, String columnName) {
super(dataSource, incrementerName, columnName);
}