Skip to content

Commit da0a36b

Browse files
committed
Upgrade to NullAway 0.12.10 and refine nullability
Closes gh-35492
1 parent 8ac5cdb commit da0a36b

File tree

15 files changed

+30
-49
lines changed

15 files changed

+30
-49
lines changed

gradle/spring-module.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,6 @@ publishing {
119119
components.java.withVariantsFromConfiguration(configurations.testFixturesApiElements) { skip() }
120120
components.java.withVariantsFromConfiguration(configurations.testFixturesRuntimeElements) { skip() }
121121

122+
nullability {
123+
nullAwayVersion = "0.12.10"
124+
}

spring-core/src/main/java/org/springframework/util/function/SingletonSupplier.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
* @since 5.1
4040
* @param <T> the type of results supplied by this supplier
4141
*/
42-
public class SingletonSupplier<T> implements Supplier<@Nullable T> {
42+
public class SingletonSupplier<T extends @Nullable Object> implements Supplier<T> {
4343

4444
private final @Nullable Supplier<? extends @Nullable T> instanceSupplier;
4545

spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcTemplate.java

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,6 @@ protected Connection createConnectionProxy(Connection con) {
441441
}
442442

443443
@Override
444-
@SuppressWarnings("NullAway") // See https://github.com/uber/NullAway/issues/1075
445444
public void execute(String sql) throws DataAccessException {
446445
if (logger.isDebugEnabled()) {
447446
logger.debug("Executing SQL statement [" + sql + "]");
@@ -464,7 +463,6 @@ public String getSql() {
464463
}
465464

466465
@Override
467-
@SuppressWarnings("NullAway") // See https://github.com/uber/NullAway/issues/1075
468466
public <T extends @Nullable Object> T query(String sql, ResultSetExtractor<T> rse) throws DataAccessException {
469467
Assert.notNull(sql, "SQL must not be null");
470468
Assert.notNull(rse, "ResultSetExtractor must not be null");
@@ -475,7 +473,7 @@ public String getSql() {
475473
// Callback to execute the query.
476474
class QueryStatementCallback implements StatementCallback<T>, SqlProvider {
477475
@Override
478-
public @Nullable T doInStatement(Statement stmt) throws SQLException {
476+
public T doInStatement(Statement stmt) throws SQLException {
479477
ResultSet rs = null;
480478
try {
481479
rs = stmt.executeQuery(sql);
@@ -495,7 +493,6 @@ public String getSql() {
495493
}
496494

497495
@Override
498-
@SuppressWarnings("NullAway") // See https://github.com/uber/NullAway/issues/1075
499496
public void query(String sql, RowCallbackHandler rch) throws DataAccessException {
500497
query(sql, new RowCallbackHandlerResultSetExtractor(rch, this.maxRows));
501498
}
@@ -544,7 +541,6 @@ public String getSql() {
544541
}
545542

546543
@Override
547-
@SuppressWarnings("NullAway") // See https://github.com/uber/NullAway/issues/1075
548544
public <T> List<@Nullable T> queryForList(String sql, Class<T> elementType) throws DataAccessException {
549545
return query(sql, getSingleColumnRowMapper(elementType));
550546
}
@@ -725,7 +721,7 @@ private String appendSql(@Nullable String sql, String statement) {
725721
* @return an arbitrary result object, as returned by the ResultSetExtractor
726722
* @throws DataAccessException if there is any problem
727723
*/
728-
public <T> @Nullable T query(
724+
public <T extends @Nullable Object> T query(
729725
PreparedStatementCreator psc, @Nullable PreparedStatementSetter pss, ResultSetExtractor<T> rse)
730726
throws DataAccessException {
731727

@@ -751,13 +747,11 @@ private String appendSql(@Nullable String sql, String statement) {
751747
}
752748

753749
@Override
754-
@SuppressWarnings("NullAway") // See https://github.com/uber/NullAway/issues/1075
755750
public <T extends @Nullable Object> T query(PreparedStatementCreator psc, ResultSetExtractor<T> rse) throws DataAccessException {
756751
return query(psc, null, rse);
757752
}
758753

759754
@Override
760-
@SuppressWarnings("NullAway") // See https://github.com/uber/NullAway/issues/1075
761755
public <T extends @Nullable Object> T query(String sql, @Nullable PreparedStatementSetter pss, ResultSetExtractor<T> rse) throws DataAccessException {
762756
return query(new SimplePreparedStatementCreator(sql), pss, rse);
763757
}
@@ -779,13 +773,11 @@ private String appendSql(@Nullable String sql, String statement) {
779773
}
780774

781775
@Override
782-
@SuppressWarnings("NullAway") // See https://github.com/uber/NullAway/issues/1075
783776
public void query(PreparedStatementCreator psc, RowCallbackHandler rch) throws DataAccessException {
784777
query(psc, new RowCallbackHandlerResultSetExtractor(rch, this.maxRows));
785778
}
786779

787780
@Override
788-
@SuppressWarnings("NullAway") // See https://github.com/uber/NullAway/issues/1075
789781
public void query(String sql, @Nullable PreparedStatementSetter pss, RowCallbackHandler rch) throws DataAccessException {
790782
query(sql, pss, new RowCallbackHandlerResultSetExtractor(rch, this.maxRows));
791783
}
@@ -930,20 +922,17 @@ public void query(String sql, RowCallbackHandler rch, @Nullable Object @Nullable
930922
}
931923

932924
@Override
933-
@SuppressWarnings("NullAway") // See https://github.com/uber/NullAway/issues/1075
934925
public <T> List<@Nullable T> queryForList(String sql, @Nullable Object @Nullable [] args, int[] argTypes, Class<T> elementType) throws DataAccessException {
935926
return query(sql, args, argTypes, getSingleColumnRowMapper(elementType));
936927
}
937928

938929
@Deprecated(since = "5.3")
939930
@Override
940-
@SuppressWarnings("NullAway") // See https://github.com/uber/NullAway/issues/1075
941931
public <T> List<@Nullable T> queryForList(String sql, @Nullable Object @Nullable [] args, Class<T> elementType) throws DataAccessException {
942932
return query(sql, newArgPreparedStatementSetter(args), getSingleColumnRowMapper(elementType));
943933
}
944934

945935
@Override
946-
@SuppressWarnings("NullAway") // See https://github.com/uber/NullAway/issues/1075
947936
public <T> List<@Nullable T> queryForList(String sql, Class<T> elementType, @Nullable Object @Nullable ... args) throws DataAccessException {
948937
return query(sql, newArgPreparedStatementSetter(args), getSingleColumnRowMapper(elementType));
949938
}
@@ -1413,7 +1402,7 @@ else if (param.getResultSetExtractor() != null) {
14131402
* @return the RowMapper to use
14141403
* @see SingleColumnRowMapper
14151404
*/
1416-
protected <T extends @Nullable Object> RowMapper<T> getSingleColumnRowMapper(Class<T> requiredType) {
1405+
protected <T> RowMapper<@Nullable T> getSingleColumnRowMapper(Class<T> requiredType) {
14171406
return new SingleColumnRowMapper<>(requiredType);
14181407
}
14191408

spring-jdbc/src/main/java/org/springframework/jdbc/core/RowMapperResultSetExtractor.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
import java.util.ArrayList;
2222
import java.util.List;
2323

24-
import org.jspecify.annotations.Nullable;
25-
2624
import org.springframework.util.Assert;
2725

2826
/**
@@ -61,7 +59,7 @@
6159
* @see JdbcTemplate
6260
* @see org.springframework.jdbc.object.MappingSqlQuery
6361
*/
64-
public class RowMapperResultSetExtractor<T extends @Nullable Object> implements ResultSetExtractor<List<T>> {
62+
public class RowMapperResultSetExtractor<T> implements ResultSetExtractor<List<T>> {
6563

6664
private final RowMapper<T> rowMapper;
6765

spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/NamedParameterJdbcTemplate.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,15 +294,13 @@ public <T> List<T> query(String sql, RowMapper<T> rowMapper) throws DataAccessEx
294294
}
295295

296296
@Override
297-
@SuppressWarnings("NullAway") // See https://github.com/uber/NullAway/issues/1075
298297
public <T> List<@Nullable T> queryForList(String sql, SqlParameterSource paramSource, Class<T> elementType)
299298
throws DataAccessException {
300299

301300
return query(sql, paramSource, new SingleColumnRowMapper<>(elementType));
302301
}
303302

304303
@Override
305-
@SuppressWarnings("NullAway") // See https://github.com/uber/NullAway/issues/1075
306304
public <T> List<@Nullable T> queryForList(String sql, Map<String, ?> paramMap, Class<T> elementType)
307305
throws DataAccessException {
308306

spring-jdbc/src/main/java/org/springframework/jdbc/core/simple/AbstractJdbcInsert.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,6 @@ private Number executeInsertAndReturnKeyInternal(List<?> values) {
448448
/**
449449
* Delegate method to execute the insert, generating any number of keys.
450450
*/
451-
@SuppressWarnings("NullAway") // See https://github.com/uber/NullAway/issues/1075
452451
private KeyHolder executeInsertAndReturnKeyHolderInternal(List<?> values) {
453452
if (logger.isDebugEnabled()) {
454453
logger.debug("The following parameters are used for call " + getInsertString() + " with: " + values);

spring-jdbc/src/main/java/org/springframework/jdbc/core/simple/DefaultJdbcClient.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ public ResultQuerySpec query() {
240240
}
241241

242242
@Override
243-
@SuppressWarnings({"unchecked", "NullAway"}) // See https://github.com/uber/NullAway/issues/1075
243+
@SuppressWarnings("unchecked")
244244
public <T> MappedQuerySpec<@Nullable T> query(Class<T> mappedClass) {
245245
RowMapper<?> rowMapper = rowMapperCache.computeIfAbsent(mappedClass, key ->
246246
BeanUtils.isSimpleProperty(mappedClass) ?
@@ -342,7 +342,6 @@ public SqlRowSet rowSet() {
342342
}
343343

344344
@Override
345-
@SuppressWarnings("NullAway") // See https://github.com/uber/NullAway/issues/1075
346345
public List<@Nullable Object> singleColumn() {
347346
return classicOps.queryForList(sql, Object.class, indexedParams.toArray());
348347
}
@@ -362,13 +361,11 @@ public SqlRowSet rowSet() {
362361
}
363362

364363
@Override
365-
@SuppressWarnings("NullAway") // See https://github.com/uber/NullAway/issues/1075
366364
public Map<String, @Nullable Object> singleRow() {
367365
return namedParamOps.queryForMap(sql, namedParamSource);
368366
}
369367

370368
@Override
371-
@SuppressWarnings("NullAway") // See https://github.com/uber/NullAway/issues/1075
372369
public List<@Nullable Object> singleColumn() {
373370
return namedParamOps.queryForList(sql, namedParamSource, Object.class);
374371
}

spring-jdbc/src/main/java/org/springframework/jdbc/core/simple/JdbcClient.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,6 @@ interface ResultQuerySpec {
391391
* @see #optionalValue()
392392
* @see DataAccessUtils#requiredSingleResult(Collection)
393393
*/
394-
@SuppressWarnings("NullAway") // See https://github.com/uber/NullAway/issues/1075
395394
default Object singleValue() {
396395
return DataAccessUtils.requiredSingleResult(singleColumn());
397396
}
@@ -403,7 +402,6 @@ default Object singleValue() {
403402
* @see #singleValue()
404403
* @see DataAccessUtils#optionalResult(Collection)
405404
*/
406-
@SuppressWarnings("NullAway") // See https://github.com/uber/NullAway/issues/1075
407405
default Optional<Object> optionalValue() {
408406
return DataAccessUtils.optionalResult(singleColumn());
409407
}

spring-test/src/main/java/org/springframework/test/web/reactive/server/DefaultWebTestClient.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,6 @@ public <T extends S, R> T value(Function<@Nullable B, @Nullable R> bodyMapper, M
596596
}
597597

598598
@Override
599-
@SuppressWarnings("NullAway") // https://github.com/uber/NullAway/issues/1129
600599
public <T extends S> T value(Consumer<@Nullable B> consumer) {
601600
this.result.assertWithDiagnostics(() -> consumer.accept(this.result.getResponseBody()));
602601
return self();
@@ -620,7 +619,7 @@ public EntityExchangeResult<B> returnResult() {
620619
}
621620

622621

623-
private static class DefaultListBodySpec<E> extends DefaultBodySpec<List<@Nullable E>, ListBodySpec<E>>
622+
private static class DefaultListBodySpec<E extends @Nullable Object> extends DefaultBodySpec<List<E>, ListBodySpec<E>>
624623
implements ListBodySpec<E> {
625624

626625
DefaultListBodySpec(EntityExchangeResult<List<E>> result) {
@@ -629,7 +628,7 @@ private static class DefaultListBodySpec<E> extends DefaultBodySpec<List<@Nullab
629628

630629
@Override
631630
public ListBodySpec<E> hasSize(int size) {
632-
List<@Nullable E> actual = getResult().getResponseBody();
631+
List<E> actual = getResult().getResponseBody();
633632
String message = "Response body does not contain " + size + " elements";
634633
getResult().assertWithDiagnostics(() ->
635634
AssertionErrors.assertEquals(message, size, (actual != null ? actual.size() : 0)));
@@ -638,9 +637,9 @@ public ListBodySpec<E> hasSize(int size) {
638637

639638
@Override
640639
@SuppressWarnings("unchecked")
641-
public ListBodySpec<E> contains(@Nullable E... elements) {
640+
public ListBodySpec<E> contains(E... elements) {
642641
List<E> expected = Arrays.asList(elements);
643-
List<@Nullable E> actual = getResult().getResponseBody();
642+
List<E> actual = getResult().getResponseBody();
644643
String message = "Response body does not contain " + expected;
645644
getResult().assertWithDiagnostics(() ->
646645
AssertionErrors.assertTrue(message, (actual != null && actual.containsAll(expected))));
@@ -649,17 +648,17 @@ public ListBodySpec<E> contains(@Nullable E... elements) {
649648

650649
@Override
651650
@SuppressWarnings("unchecked")
652-
public ListBodySpec<E> doesNotContain(@Nullable E... elements) {
651+
public ListBodySpec<E> doesNotContain(E... elements) {
653652
List<E> expected = Arrays.asList(elements);
654-
List<@Nullable E> actual = getResult().getResponseBody();
653+
List<E> actual = getResult().getResponseBody();
655654
String message = "Response body should not have contained " + expected;
656655
getResult().assertWithDiagnostics(() ->
657656
AssertionErrors.assertTrue(message, (actual == null || !actual.containsAll(expected))));
658657
return this;
659658
}
660659

661660
@Override
662-
public EntityExchangeResult<List<@Nullable E>> returnResult() {
661+
public EntityExchangeResult<List<E>> returnResult() {
663662
return getResult();
664663
}
665664
}

spring-test/src/main/java/org/springframework/test/web/reactive/server/WebTestClient.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -975,7 +975,7 @@ interface BodySpec<B, S extends BodySpec<B, S>> {
975975
*
976976
* @param <E> the body list element type
977977
*/
978-
interface ListBodySpec<E> extends BodySpec<List<@Nullable E>, ListBodySpec<E>> {
978+
interface ListBodySpec<E extends @Nullable Object> extends BodySpec<List<E>, ListBodySpec<E>> {
979979

980980
/**
981981
* Assert the extracted list of values is of the given size.
@@ -988,14 +988,14 @@ interface ListBodySpec<E> extends BodySpec<List<@Nullable E>, ListBodySpec<E>> {
988988
* @param elements the elements to check
989989
*/
990990
@SuppressWarnings("unchecked")
991-
ListBodySpec<E> contains(@Nullable E... elements);
991+
ListBodySpec<E> contains(E... elements);
992992

993993
/**
994994
* Assert the extracted list of values doesn't contain the given elements.
995995
* @param elements the elements to check
996996
*/
997997
@SuppressWarnings("unchecked")
998-
ListBodySpec<E> doesNotContain(@Nullable E... elements);
998+
ListBodySpec<E> doesNotContain(E... elements);
999999
}
10001000

10011001

0 commit comments

Comments
 (0)