diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/ArgumentTypePreparedStatementSetter.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/ArgumentTypePreparedStatementSetter.java index c174e3e039f..ab8e54d1ff2 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/ArgumentTypePreparedStatementSetter.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/ArgumentTypePreparedStatementSetter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -45,10 +45,8 @@ 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 @Nullable [] args, int @Nullable [] argTypes) { - if ((args != null && argTypes == null) || (args == null && argTypes != null) || - (args != null && args.length != argTypes.length)) { + if ((args == null && argTypes != null) || (args != null && (argTypes == null || args.length != argTypes.length))) { throw new InvalidDataAccessApiUsageException("args and argTypes parameters must match"); } this.args = args; diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/SingleConnectionDataSource.java b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/SingleConnectionDataSource.java index 6fdef5d1ffc..4e5e3dffc72 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/SingleConnectionDataSource.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/SingleConnectionDataSource.java @@ -179,7 +179,7 @@ public class SingleConnectionDataSource extends DriverManagerDataSource @Override - @SuppressWarnings("NullAway") + @SuppressWarnings("NullAway") // Lazy initialization public Connection getConnection() throws SQLException { this.connectionLock.lock(); try { diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseFactory.java b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseFactory.java index d7205235ca2..0599a7158be 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseFactory.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseFactory.java @@ -159,7 +159,7 @@ public class EmbeddedDatabaseFactory { * Factory method that returns the {@linkplain EmbeddedDatabase embedded database} * instance, which is also a {@link DataSource}. */ - @SuppressWarnings("NullAway") + @SuppressWarnings("NullAway") // Lazy initialization public EmbeddedDatabase getDatabase() { if (this.dataSource == null) { initDatabase(); diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/support/incrementer/AbstractDataFieldMaxValueIncrementer.java b/spring-jdbc/src/main/java/org/springframework/jdbc/support/incrementer/AbstractDataFieldMaxValueIncrementer.java index 8022eec12c9..b9f8093427a 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/support/incrementer/AbstractDataFieldMaxValueIncrementer.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/support/incrementer/AbstractDataFieldMaxValueIncrementer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -76,7 +76,7 @@ public abstract class AbstractDataFieldMaxValueIncrementer implements DataFieldM /** * Return the data source to retrieve the value from. */ - @SuppressWarnings("NullAway") + @SuppressWarnings("NullAway") // Lazy initialization public DataSource getDataSource() { return this.dataSource; } @@ -91,7 +91,7 @@ public abstract class AbstractDataFieldMaxValueIncrementer implements DataFieldM /** * Return the name of the sequence/table. */ - @SuppressWarnings("NullAway") + @SuppressWarnings("NullAway") // Lazy initialization public String getIncrementerName() { return this.incrementerName; } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/support/incrementer/AbstractIdentityColumnMaxValueIncrementer.java b/spring-jdbc/src/main/java/org/springframework/jdbc/support/incrementer/AbstractIdentityColumnMaxValueIncrementer.java index 39b400ad843..dcaaeb0eca3 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/support/incrementer/AbstractIdentityColumnMaxValueIncrementer.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/support/incrementer/AbstractIdentityColumnMaxValueIncrementer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,10 +23,13 @@ import java.sql.Statement; import javax.sql.DataSource; +import org.jspecify.annotations.Nullable; + import org.springframework.dao.DataAccessException; import org.springframework.dao.DataAccessResourceFailureException; import org.springframework.jdbc.datasource.DataSourceUtils; import org.springframework.jdbc.support.JdbcUtils; +import org.springframework.util.Assert; /** * Abstract base class for {@link DataFieldMaxValueIncrementer} implementations @@ -41,7 +44,7 @@ public abstract class AbstractIdentityColumnMaxValueIncrementer extends Abstract private boolean deleteSpecificValues = false; /** The current cache of values. */ - private long[] valueCache; + private long @Nullable [] valueCache; /** The next id to serve from the value cache. */ private int nextValueIndex = -1; @@ -53,11 +56,9 @@ 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); } @@ -120,6 +121,7 @@ public abstract class AbstractIdentityColumnMaxValueIncrementer extends Abstract DataSourceUtils.releaseConnection(con, getDataSource()); } } + Assert.state(this.valueCache != null, "The cache of values can't be null"); return this.valueCache[this.nextValueIndex++]; }