Add more @Nullable parameters based on null usage

Issue: SPR-15540
This commit is contained in:
Sebastien Deleuze
2017-05-31 21:35:52 +02:00
parent f9b319d3ba
commit 1f28825f9d
219 changed files with 441 additions and 355 deletions

View File

@@ -31,6 +31,7 @@ import org.springframework.core.io.ResourceLoader;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternUtils;
import org.springframework.lang.Nullable;
/**
* {@link FactoryBean} implementation that takes a list of location Strings
@@ -60,7 +61,7 @@ public class SortedResourcesFactoryBean extends AbstractFactoryBean<Resource[]>
@Override
public void setResourceLoader(ResourceLoader resourceLoader) {
public void setResourceLoader(@Nullable ResourceLoader resourceLoader) {
this.resourcePatternResolver = ResourcePatternUtils.getResourcePatternResolver(resourceLoader);
}

View File

@@ -627,7 +627,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
* @throws DataAccessException if there is any problem
*/
public <T> T query(
PreparedStatementCreator psc, final PreparedStatementSetter pss, final ResultSetExtractor<T> rse)
PreparedStatementCreator psc, @Nullable final PreparedStatementSetter pss, final ResultSetExtractor<T> rse)
throws DataAccessException {
Assert.notNull(rse, "ResultSetExtractor must not be null");

View File

@@ -193,7 +193,7 @@ public abstract class StatementCreatorUtils {
* @see SqlTypeValue
*/
private static void setParameterValueInternal(PreparedStatement ps, int paramIndex, int sqlType,
String typeName, Integer scale, Object inValue) throws SQLException {
@Nullable String typeName, @Nullable Integer scale, Object inValue) throws SQLException {
String typeNameToUse = typeName;
int sqlTypeToUse = sqlType;

View File

@@ -37,6 +37,7 @@ import org.springframework.jdbc.core.SqlParameter;
import org.springframework.jdbc.core.SqlRowSetResultSetExtractor;
import org.springframework.jdbc.support.KeyHolder;
import org.springframework.jdbc.support.rowset.SqlRowSet;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -301,7 +302,7 @@ public class NamedParameterJdbcTemplate implements NamedParameterJdbcOperations
@Override
public int update(
String sql, SqlParameterSource paramSource, KeyHolder generatedKeyHolder, String[] keyColumnNames)
String sql, SqlParameterSource paramSource, KeyHolder generatedKeyHolder, @Nullable String[] keyColumnNames)
throws DataAccessException {
ParsedSql parsedSql = getParsedSql(sql);

View File

@@ -256,7 +256,7 @@ public abstract class NamedParameterUtils {
* @return the SQL statement with substituted parameters
* @see #parseSqlStatement
*/
public static String substituteNamedParameters(ParsedSql parsedSql, SqlParameterSource paramSource) {
public static String substituteNamedParameters(ParsedSql parsedSql, @Nullable SqlParameterSource paramSource) {
String originalSql = parsedSql.getOriginalSql();
StringBuilder actualSql = new StringBuilder();
List<String> paramNames = parsedSql.getParameterNames();

View File

@@ -22,6 +22,7 @@ import java.sql.Statement;
import javax.sql.DataSource;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.lang.Nullable;
import org.springframework.transaction.CannotCreateTransactionException;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionSystemException;
@@ -413,7 +414,7 @@ public class DataSourceTransactionManager extends AbstractPlatformTransactionMan
private boolean mustRestoreAutoCommit;
public void setConnectionHolder(ConnectionHolder connectionHolder, boolean newConnectionHolder) {
public void setConnectionHolder(@Nullable ConnectionHolder connectionHolder, boolean newConnectionHolder) {
super.setConnectionHolder(connectionHolder);
this.newConnectionHolder = newConnectionHolder;
}

View File

@@ -22,6 +22,7 @@ import java.sql.Savepoint;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.lang.Nullable;
import org.springframework.transaction.CannotCreateTransactionException;
import org.springframework.transaction.NestedTransactionNotSupportedException;
import org.springframework.transaction.SavepointManager;
@@ -56,7 +57,7 @@ public abstract class JdbcTransactionObjectSupport implements SavepointManager,
private boolean savepointAllowed = false;
public void setConnectionHolder(ConnectionHolder connectionHolder) {
public void setConnectionHolder(@Nullable ConnectionHolder connectionHolder) {
this.connectionHolder = connectionHolder;
}

View File

@@ -30,6 +30,7 @@ import org.apache.commons.logging.LogFactory;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.EncodedResource;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
@@ -164,7 +165,7 @@ public abstract class ScriptUtils {
* @param statements the list that will contain the individual statements
* @throws ScriptException if an error occurred while splitting the SQL script
*/
public static void splitSqlScript(EncodedResource resource, String script, String separator, String commentPrefix,
public static void splitSqlScript(@Nullable EncodedResource resource, String script, String separator, String commentPrefix,
String blockCommentStartDelimiter, String blockCommentEndDelimiter, List<String> statements)
throws ScriptException {

View File

@@ -107,7 +107,7 @@ public abstract class SqlQuery<T> extends SqlOperation {
* @return a List of objects, one per row of the ResultSet. Normally all these
* will be of the same class, although it is possible to use different types.
*/
public List<T> execute(Object[] params, Map<?, ?> context) throws DataAccessException {
public List<T> execute(Object[] params, @Nullable Map<?, ?> context) throws DataAccessException {
validateParameters(params);
RowMapper<T> rowMapper = newRowMapper(params, context);
return getJdbcTemplate().query(newPreparedStatementCreator(params), rowMapper);
@@ -143,7 +143,7 @@ public abstract class SqlQuery<T> extends SqlOperation {
* @param p1 single int parameter
* @param context the contextual information for object creation
*/
public List<T> execute(int p1, Map<?, ?> context) throws DataAccessException {
public List<T> execute(int p1, @Nullable Map<?, ?> context) throws DataAccessException {
return execute(new Object[] {p1}, context);
}
@@ -161,7 +161,7 @@ public abstract class SqlQuery<T> extends SqlOperation {
* @param p2 second int parameter
* @param context the contextual information for object creation
*/
public List<T> execute(int p1, int p2, Map<?, ?> context) throws DataAccessException {
public List<T> execute(int p1, int p2, @Nullable Map<?, ?> context) throws DataAccessException {
return execute(new Object[] {p1, p2}, context);
}
@@ -179,7 +179,7 @@ public abstract class SqlQuery<T> extends SqlOperation {
* @param p1 single long parameter
* @param context the contextual information for object creation
*/
public List<T> execute(long p1, Map<?, ?> context) throws DataAccessException {
public List<T> execute(long p1, @Nullable Map<?, ?> context) throws DataAccessException {
return execute(new Object[] {p1}, context);
}
@@ -196,7 +196,7 @@ public abstract class SqlQuery<T> extends SqlOperation {
* @param p1 single String parameter
* @param context the contextual information for object creation
*/
public List<T> execute(String p1, Map<?, ?> context) throws DataAccessException {
public List<T> execute(String p1, @Nullable Map<?, ?> context) throws DataAccessException {
return execute(new Object[] {p1}, context);
}
@@ -220,7 +220,7 @@ public abstract class SqlQuery<T> extends SqlOperation {
* @return a List of objects, one per row of the ResultSet. Normally all these
* will be of the same class, although it is possible to use different types.
*/
public List<T> executeByNamedParam(Map<String, ?> paramMap, Map<?, ?> context) throws DataAccessException {
public List<T> executeByNamedParam(Map<String, ?> paramMap, @Nullable Map<?, ?> context) throws DataAccessException {
validateNamedParameters(paramMap);
ParsedSql parsedSql = getParsedSql();
MapSqlParameterSource paramSource = new MapSqlParameterSource(paramMap);
@@ -250,7 +250,7 @@ public abstract class SqlQuery<T> extends SqlOperation {
* @see org.springframework.dao.support.DataAccessUtils#singleResult
*/
@Nullable
public T findObject(Object[] params, Map<?, ?> context) throws DataAccessException {
public T findObject(Object[] params, @Nullable Map<?, ?> context) throws DataAccessException {
List<T> results = execute(params, context);
return DataAccessUtils.singleResult(results);
}
@@ -266,7 +266,7 @@ public abstract class SqlQuery<T> extends SqlOperation {
* Convenient method to find a single object given a single int parameter
* and a context.
*/
public T findObject(int p1, Map<?, ?> context) throws DataAccessException {
public T findObject(int p1, @Nullable Map<?, ?> context) throws DataAccessException {
return findObject(new Object[] {p1}, context);
}
@@ -281,7 +281,7 @@ public abstract class SqlQuery<T> extends SqlOperation {
* Convenient method to find a single object given two int parameters
* and a context.
*/
public T findObject(int p1, int p2, Map<?, ?> context) throws DataAccessException {
public T findObject(int p1, int p2, @Nullable Map<?, ?> context) throws DataAccessException {
return findObject(new Object[] {p1, p2}, context);
}
@@ -296,7 +296,7 @@ public abstract class SqlQuery<T> extends SqlOperation {
* Convenient method to find a single object given a single long parameter
* and a context.
*/
public T findObject(long p1, Map<?, ?> context) throws DataAccessException {
public T findObject(long p1, @Nullable Map<?, ?> context) throws DataAccessException {
return findObject(new Object[] {p1}, context);
}
@@ -311,7 +311,7 @@ public abstract class SqlQuery<T> extends SqlOperation {
* Convenient method to find a single object given a single String parameter
* and a context.
*/
public T findObject(String p1, Map<?, ?> context) throws DataAccessException {
public T findObject(String p1, @Nullable Map<?, ?> context) throws DataAccessException {
return findObject(new Object[] {p1}, context);
}
@@ -333,7 +333,7 @@ public abstract class SqlQuery<T> extends SqlOperation {
* @return a List of objects, one per row of the ResultSet. Normally all these
* will be of the same class, although it is possible to use different types.
*/
public T findObjectByNamedParam(Map<String, ?> paramMap, Map<?, ?> context) throws DataAccessException {
public T findObjectByNamedParam(Map<String, ?> paramMap, @Nullable Map<?, ?> context) throws DataAccessException {
List<T> results = executeByNamedParam(paramMap, context);
return DataAccessUtils.singleResult(results);
}