Add nullability annotations to module/spring-boot-jooq

See gh-46587
This commit is contained in:
Moritz Halbritter
2025-08-04 11:27:41 +02:00
parent d89b8533a4
commit dfac782da3
8 changed files with 22 additions and 9 deletions
@@ -23,6 +23,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jooq.ExecuteContext;
import org.jooq.SQLDialect;
import org.jspecify.annotations.Nullable;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator;
@@ -117,7 +118,7 @@ final class DefaultExceptionTranslatorExecuteListener implements ExceptionTransl
: new SQLExceptionSubclassTranslator();
}
private String getSpringDbName(SQLDialect dialect) {
private @Nullable String getSpringDbName(@Nullable SQLDialect dialect) {
return (dialect != null && dialect.thirdParty() != null) ? dialect.thirdParty().springDbName() : null;
}
@@ -133,6 +133,7 @@ public final class JooqAutoConfiguration {
throw new JaxbNotAvailableException();
}
Resource resource = properties.getConfig();
Assert.state(resource != null, "'resource' must not be null");
Assert.state(resource.exists(),
() -> "Resource %s set in spring.jooq.config does not exist".formatted(resource));
try (InputStream stream = resource.getInputStream()) {
@@ -19,6 +19,7 @@ package org.springframework.boot.jooq.autoconfigure;
import javax.sql.DataSource;
import org.jooq.SQLDialect;
import org.jspecify.annotations.Nullable;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.core.io.Resource;
@@ -37,26 +38,26 @@ public class JooqProperties {
/**
* SQL dialect to use. Auto-detected by default.
*/
private SQLDialect sqlDialect;
private @Nullable SQLDialect sqlDialect;
/**
* Location of the jOOQ config file.
*/
private Resource config;
private @Nullable Resource config;
public SQLDialect getSqlDialect() {
public @Nullable SQLDialect getSqlDialect() {
return this.sqlDialect;
}
public void setSqlDialect(SQLDialect sqlDialect) {
public void setSqlDialect(@Nullable SQLDialect sqlDialect) {
this.sqlDialect = sqlDialect;
}
public Resource getConfig() {
public @Nullable Resource getConfig() {
return this.config;
}
public void setConfig(Resource config) {
public void setConfig(@Nullable Resource config) {
this.config = config;
}
@@ -17,6 +17,7 @@
package org.springframework.boot.jooq.autoconfigure;
import org.jooq.DSLContext;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
@@ -35,7 +36,7 @@ class NoDslContextBeanFailureAnalyzer extends AbstractFailureAnalyzer<NoSuchBean
}
@Override
protected FailureAnalysis analyze(Throwable rootFailure, NoSuchBeanDefinitionException cause) {
protected @Nullable FailureAnalysis analyze(Throwable rootFailure, NoSuchBeanDefinitionException cause) {
if (DSLContext.class.equals(cause.getBeanType()) && hasR2dbcAutoConfiguration()) {
return new FailureAnalysis(
"jOOQ has not been auto-configured as R2DBC has been auto-configured in favor of JDBC and jOOQ "
@@ -23,6 +23,7 @@ import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.DefaultTransactionDefinition;
import org.springframework.util.Assert;
/**
* Allows Spring Transaction to be used with jOOQ.
@@ -61,6 +62,7 @@ public class SpringTransactionProvider implements TransactionProvider {
private TransactionStatus getTransactionStatus(TransactionContext ctx) {
SpringTransaction transaction = (SpringTransaction) ctx.transaction();
Assert.state(transaction != null, "'transaction' must not be null");
return transaction.getTxStatus();
}
@@ -25,6 +25,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jooq.SQLDialect;
import org.jooq.tools.jdbc.JDBCUtils;
import org.jspecify.annotations.Nullable;
/**
* Utility to lookup well known {@link SQLDialect SQLDialects} from a {@link DataSource}.
@@ -45,7 +46,7 @@ final class SqlDialectLookup {
* @param dataSource the source {@link DataSource}
* @return the most suitable {@link SQLDialect}
*/
static SQLDialect getDialect(DataSource dataSource) {
static SQLDialect getDialect(@Nullable DataSource dataSource) {
try (Connection connection = (dataSource != null) ? dataSource.getConnection() : null) {
return JDBCUtils.dialect(connection);
}
@@ -17,4 +17,7 @@
/**
* Auto-configuration for jOOQ.
*/
@NullMarked
package org.springframework.boot.jooq.autoconfigure;
import org.jspecify.annotations.NullMarked;
@@ -19,4 +19,7 @@
*
* @see org.springframework.boot.json.JsonParser
*/
@NullMarked
package org.springframework.boot.jooq;
import org.jspecify.annotations.NullMarked;