Add nullability annotations to module/spring-boot-flyway

See gh-46587
This commit is contained in:
Moritz Halbritter
2025-07-30 14:56:56 +02:00
parent 5ac6dfcffb
commit eb31180a64
13 changed files with 128 additions and 100 deletions
@@ -38,6 +38,7 @@ import org.flywaydb.core.extensibility.ConfigurationExtension;
import org.flywaydb.database.oracle.OracleConfigurationExtension;
import org.flywaydb.database.postgresql.PostgreSQLConfigurationExtension;
import org.flywaydb.database.sqlserver.SQLServerConfigurationExtension;
import org.jspecify.annotations.Nullable;
import org.springframework.aot.hint.RuntimeHints;
import org.springframework.aot.hint.RuntimeHintsRegistrar;
@@ -177,14 +178,14 @@ public final class FlywayAutoConfiguration {
return configuration.load();
}
private void configureDataSource(FluentConfiguration configuration, DataSource flywayDataSource,
DataSource dataSource, FlywayConnectionDetails connectionDetails) {
private void configureDataSource(FluentConfiguration configuration, @Nullable DataSource flywayDataSource,
@Nullable DataSource dataSource, FlywayConnectionDetails connectionDetails) {
DataSource migrationDataSource = getMigrationDataSource(flywayDataSource, dataSource, connectionDetails);
configuration.dataSource(migrationDataSource);
}
private DataSource getMigrationDataSource(DataSource flywayDataSource, DataSource dataSource,
FlywayConnectionDetails connectionDetails) {
private DataSource getMigrationDataSource(@Nullable DataSource flywayDataSource,
@Nullable DataSource dataSource, FlywayConnectionDetails connectionDetails) {
if (flywayDataSource != null) {
return flywayDataSource;
}
@@ -424,7 +425,7 @@ public final class FlywayAutoConfiguration {
}
@Override
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
String value = ObjectUtils.nullSafeToString(source);
return MigrationVersion.fromVersion(value);
}
@@ -457,7 +458,7 @@ public final class FlywayAutoConfiguration {
static class FlywayAutoConfigurationRuntimeHints implements RuntimeHintsRegistrar {
@Override
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) {
hints.resources().registerPattern("db/migration/*");
}
@@ -475,22 +476,22 @@ public final class FlywayAutoConfiguration {
}
@Override
public String getUsername() {
public @Nullable String getUsername() {
return this.properties.getUser();
}
@Override
public String getPassword() {
public @Nullable String getPassword() {
return this.properties.getPassword();
}
@Override
public String getJdbcUrl() {
public @Nullable String getJdbcUrl() {
return this.properties.getUrl();
}
@Override
public String getDriverClassName() {
public @Nullable String getDriverClassName() {
return this.properties.getDriverClassName();
}
@@ -574,7 +575,7 @@ public final class FlywayAutoConfiguration {
*/
static class Extension<E extends ConfigurationExtension> {
private SingletonSupplier<E> extension;
private final SingletonSupplier<E> extension;
Extension(FluentConfiguration configuration, Class<E> type, String name) {
this.extension = SingletonSupplier.of(() -> {
@@ -16,6 +16,8 @@
package org.springframework.boot.flyway.autoconfigure;
import org.jspecify.annotations.Nullable;
import org.springframework.boot.autoconfigure.service.connection.ConnectionDetails;
import org.springframework.boot.jdbc.DatabaseDriver;
@@ -32,21 +34,21 @@ public interface FlywayConnectionDetails extends ConnectionDetails {
* required.
* @return the username for the database or {@code null}
*/
String getUsername();
@Nullable String getUsername();
/**
* Password for the database or {@code null} if no Flyway-specific configuration is
* required.
* @return the password for the database or {@code null}
*/
String getPassword();
@Nullable String getPassword();
/**
* JDBC URL for the database or {@code null} if no Flyway-specific configuration is
* required.
* @return the JDBC URL for the database or {@code null}
*/
String getJdbcUrl();
@Nullable String getJdbcUrl();
/**
* The name of the JDBC driver class. Defaults to the class name of the driver
@@ -56,7 +58,7 @@ public interface FlywayConnectionDetails extends ConnectionDetails {
* @see DatabaseDriver#fromJdbcUrl(String)
* @see DatabaseDriver#getDriverClassName()
*/
default String getDriverClassName() {
default @Nullable String getDriverClassName() {
String jdbcUrl = getJdbcUrl();
return (jdbcUrl != null) ? DatabaseDriver.fromJdbcUrl(jdbcUrl).getDriverClassName() : null;
}
@@ -17,6 +17,7 @@
package org.springframework.boot.flyway.autoconfigure;
import org.flywaydb.core.Flyway;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.core.Ordered;
@@ -33,7 +34,7 @@ public class FlywayMigrationInitializer implements InitializingBean, Ordered {
private final Flyway flyway;
private final FlywayMigrationStrategy migrationStrategy;
private final @Nullable FlywayMigrationStrategy migrationStrategy;
private int order = 0;
@@ -50,7 +51,7 @@ public class FlywayMigrationInitializer implements InitializingBean, Ordered {
* @param flyway the flyway instance
* @param migrationStrategy the migration strategy or {@code null}
*/
public FlywayMigrationInitializer(Flyway flyway, FlywayMigrationStrategy migrationStrategy) {
public FlywayMigrationInitializer(Flyway flyway, @Nullable FlywayMigrationStrategy migrationStrategy) {
Assert.notNull(flyway, "'flyway' must not be null");
this.flyway = flyway;
this.migrationStrategy = migrationStrategy;
@@ -27,6 +27,8 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.jspecify.annotations.Nullable;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.convert.DurationUnit;
@@ -83,7 +85,7 @@ public class FlywayProperties {
/**
* Default schema name managed by Flyway (case-sensitive).
*/
private String defaultSchema;
private @Nullable String defaultSchema;
/**
* Scheme names managed by Flyway (case-sensitive).
@@ -106,7 +108,7 @@ public class FlywayProperties {
* database that does not support tablespaces. Defaults to the default tablespace of
* the connection used by Flyway.
*/
private String tablespace;
private @Nullable String tablespace;
/**
* Description to tag an existing schema with when applying a baseline.
@@ -121,7 +123,7 @@ public class FlywayProperties {
/**
* Username recorded in the schema history table as having applied the migration.
*/
private String installedBy;
private @Nullable String installedBy;
/**
* Placeholders and their replacements to apply to sql migration scripts.
@@ -176,23 +178,23 @@ public class FlywayProperties {
/**
* Login user of the database to migrate.
*/
private String user;
private @Nullable String user;
/**
* Login password of the database to migrate.
*/
private String password;
private @Nullable String password;
/**
* Fully qualified name of the JDBC driver. Auto-detected based on the URL by default.
*/
private String driverClassName;
private @Nullable String driverClassName;
/**
* JDBC url of the database to migrate. If not set, the primary configured data source
* is used.
*/
private String url;
private @Nullable String url;
/**
* SQL statements to execute to initialize a connection immediately after obtaining
@@ -262,7 +264,7 @@ public class FlywayProperties {
* PowerShell executable to use for running PowerShell scripts. Default to
* "powershell" on Windows, "pwsh" on other platforms.
*/
private String powershellExecutable;
private @Nullable String powershellExecutable;
/**
* Whether Flyway should execute SQL within a transaction.
@@ -277,24 +279,24 @@ public class FlywayProperties {
/**
* Whether to batch SQL statements when executing them.
*/
private Boolean batch;
private @Nullable Boolean batch;
/**
* File to which the SQL statements of a migration dry run should be output. Requires
* Flyway Teams.
*/
private File dryRunOutput;
private @Nullable File dryRunOutput;
/**
* Rules for the built-in error handling to override specific SQL states and error
* codes. Requires Flyway Teams.
*/
private String[] errorOverrides;
private String @Nullable [] errorOverrides;
/**
* Whether to stream SQL migrations when executing them.
*/
private Boolean stream;
private @Nullable Boolean stream;
/**
* Properties to pass to the JDBC driver.
@@ -304,34 +306,34 @@ public class FlywayProperties {
/**
* Path of the Kerberos config file. Requires Flyway Teams.
*/
private String kerberosConfigFile;
private @Nullable String kerberosConfigFile;
/**
* Whether Flyway should output a table with the results of queries when executing
* migrations.
*/
private Boolean outputQueryResults;
private @Nullable Boolean outputQueryResults;
/**
* Whether Flyway should skip executing the contents of the migrations and only update
* the schema history table.
*/
private Boolean skipExecutingMigrations;
private @Nullable Boolean skipExecutingMigrations;
/**
* List of patterns that identify migrations to ignore when performing validation.
*/
private List<String> ignoreMigrationPatterns;
private @Nullable List<String> ignoreMigrationPatterns;
/**
* Whether to attempt to automatically detect SQL migration file encoding.
*/
private Boolean detectEncoding;
private @Nullable Boolean detectEncoding;
/**
* Whether to enable community database support.
*/
private Boolean communityDbSupportEnabled;
private @Nullable Boolean communityDbSupportEnabled;
private final Oracle oracle = new Oracle();
@@ -395,11 +397,11 @@ public class FlywayProperties {
this.lockRetryCount = lockRetryCount;
}
public String getDefaultSchema() {
public @Nullable String getDefaultSchema() {
return this.defaultSchema;
}
public void setDefaultSchema(String defaultSchema) {
public void setDefaultSchema(@Nullable String defaultSchema) {
this.defaultSchema = defaultSchema;
}
@@ -427,11 +429,11 @@ public class FlywayProperties {
this.table = table;
}
public String getTablespace() {
public @Nullable String getTablespace() {
return this.tablespace;
}
public void setTablespace(String tablespace) {
public void setTablespace(@Nullable String tablespace) {
this.tablespace = tablespace;
}
@@ -451,11 +453,11 @@ public class FlywayProperties {
this.baselineVersion = baselineVersion;
}
public String getInstalledBy() {
public @Nullable String getInstalledBy() {
return this.installedBy;
}
public void setInstalledBy(String installedBy) {
public void setInstalledBy(@Nullable String installedBy) {
this.installedBy = installedBy;
}
@@ -539,35 +541,35 @@ public class FlywayProperties {
this.target = target;
}
public String getUser() {
public @Nullable String getUser() {
return this.user;
}
public void setUser(String user) {
public void setUser(@Nullable String user) {
this.user = user;
}
public String getPassword() {
public @Nullable String getPassword() {
return this.password;
}
public void setPassword(String password) {
public void setPassword(@Nullable String password) {
this.password = password;
}
public String getDriverClassName() {
public @Nullable String getDriverClassName() {
return this.driverClassName;
}
public void setDriverClassName(String driverClassName) {
public void setDriverClassName(@Nullable String driverClassName) {
this.driverClassName = driverClassName;
}
public String getUrl() {
public @Nullable String getUrl() {
return this.url;
}
public void setUrl(String url) {
public void setUrl(@Nullable String url) {
this.url = url;
}
@@ -667,11 +669,11 @@ public class FlywayProperties {
this.scriptPlaceholderSuffix = scriptPlaceholderSuffix;
}
public String getPowershellExecutable() {
public @Nullable String getPowershellExecutable() {
return this.powershellExecutable;
}
public void setPowershellExecutable(String powershellExecutable) {
public void setPowershellExecutable(@Nullable String powershellExecutable) {
this.powershellExecutable = powershellExecutable;
}
@@ -691,35 +693,35 @@ public class FlywayProperties {
this.loggers = loggers;
}
public Boolean getBatch() {
public @Nullable Boolean getBatch() {
return this.batch;
}
public void setBatch(Boolean batch) {
public void setBatch(@Nullable Boolean batch) {
this.batch = batch;
}
public File getDryRunOutput() {
public @Nullable File getDryRunOutput() {
return this.dryRunOutput;
}
public void setDryRunOutput(File dryRunOutput) {
public void setDryRunOutput(@Nullable File dryRunOutput) {
this.dryRunOutput = dryRunOutput;
}
public String[] getErrorOverrides() {
public String @Nullable [] getErrorOverrides() {
return this.errorOverrides;
}
public void setErrorOverrides(String[] errorOverrides) {
public void setErrorOverrides(String @Nullable [] errorOverrides) {
this.errorOverrides = errorOverrides;
}
public Boolean getStream() {
public @Nullable Boolean getStream() {
return this.stream;
}
public void setStream(Boolean stream) {
public void setStream(@Nullable Boolean stream) {
this.stream = stream;
}
@@ -731,51 +733,51 @@ public class FlywayProperties {
this.jdbcProperties = jdbcProperties;
}
public String getKerberosConfigFile() {
public @Nullable String getKerberosConfigFile() {
return this.kerberosConfigFile;
}
public void setKerberosConfigFile(String kerberosConfigFile) {
public void setKerberosConfigFile(@Nullable String kerberosConfigFile) {
this.kerberosConfigFile = kerberosConfigFile;
}
public Boolean getOutputQueryResults() {
public @Nullable Boolean getOutputQueryResults() {
return this.outputQueryResults;
}
public void setOutputQueryResults(Boolean outputQueryResults) {
public void setOutputQueryResults(@Nullable Boolean outputQueryResults) {
this.outputQueryResults = outputQueryResults;
}
public Boolean getSkipExecutingMigrations() {
public @Nullable Boolean getSkipExecutingMigrations() {
return this.skipExecutingMigrations;
}
public void setSkipExecutingMigrations(Boolean skipExecutingMigrations) {
public void setSkipExecutingMigrations(@Nullable Boolean skipExecutingMigrations) {
this.skipExecutingMigrations = skipExecutingMigrations;
}
public List<String> getIgnoreMigrationPatterns() {
public @Nullable List<String> getIgnoreMigrationPatterns() {
return this.ignoreMigrationPatterns;
}
public void setIgnoreMigrationPatterns(List<String> ignoreMigrationPatterns) {
public void setIgnoreMigrationPatterns(@Nullable List<String> ignoreMigrationPatterns) {
this.ignoreMigrationPatterns = ignoreMigrationPatterns;
}
public Boolean getDetectEncoding() {
public @Nullable Boolean getDetectEncoding() {
return this.detectEncoding;
}
public void setDetectEncoding(final Boolean detectEncoding) {
public void setDetectEncoding(final @Nullable Boolean detectEncoding) {
this.detectEncoding = detectEncoding;
}
public Boolean getCommunityDbSupportEnabled() {
public @Nullable Boolean getCommunityDbSupportEnabled() {
return this.communityDbSupportEnabled;
}
public void setCommunityDbSupportEnabled(Boolean communityDbSupportEnabled) {
public void setCommunityDbSupportEnabled(@Nullable Boolean communityDbSupportEnabled) {
this.communityDbSupportEnabled = communityDbSupportEnabled;
}
@@ -799,54 +801,54 @@ public class FlywayProperties {
/**
* Whether to enable support for Oracle SQL*Plus commands. Requires Flyway Teams.
*/
private Boolean sqlplus;
private @Nullable Boolean sqlplus;
/**
* Whether to issue a warning rather than an error when a not-yet-supported Oracle
* SQL*Plus statement is encountered. Requires Flyway Teams.
*/
private Boolean sqlplusWarn;
private @Nullable Boolean sqlplusWarn;
/**
* Path of the Oracle Kerberos cache file. Requires Flyway Teams.
*/
private String kerberosCacheFile;
private @Nullable String kerberosCacheFile;
/**
* Location of the Oracle Wallet, used to sign in to the database automatically.
* Requires Flyway Teams.
*/
private String walletLocation;
private @Nullable String walletLocation;
public Boolean getSqlplus() {
public @Nullable Boolean getSqlplus() {
return this.sqlplus;
}
public void setSqlplus(Boolean sqlplus) {
public void setSqlplus(@Nullable Boolean sqlplus) {
this.sqlplus = sqlplus;
}
public Boolean getSqlplusWarn() {
public @Nullable Boolean getSqlplusWarn() {
return this.sqlplusWarn;
}
public void setSqlplusWarn(Boolean sqlplusWarn) {
public void setSqlplusWarn(@Nullable Boolean sqlplusWarn) {
this.sqlplusWarn = sqlplusWarn;
}
public String getKerberosCacheFile() {
public @Nullable String getKerberosCacheFile() {
return this.kerberosCacheFile;
}
public void setKerberosCacheFile(String kerberosCacheFile) {
public void setKerberosCacheFile(@Nullable String kerberosCacheFile) {
this.kerberosCacheFile = kerberosCacheFile;
}
public String getWalletLocation() {
public @Nullable String getWalletLocation() {
return this.walletLocation;
}
public void setWalletLocation(String walletLocation) {
public void setWalletLocation(@Nullable String walletLocation) {
this.walletLocation = walletLocation;
}
@@ -861,13 +863,13 @@ public class FlywayProperties {
* Whether transactional advisory locks should be used. If set to false,
* session-level locks are used instead.
*/
private Boolean transactionalLock;
private @Nullable Boolean transactionalLock;
public Boolean getTransactionalLock() {
public @Nullable Boolean getTransactionalLock() {
return this.transactionalLock;
}
public void setTransactionalLock(Boolean transactionalLock) {
public void setTransactionalLock(@Nullable Boolean transactionalLock) {
this.transactionalLock = transactionalLock;
}
@@ -881,13 +883,13 @@ public class FlywayProperties {
/**
* Path to the SQL Server Kerberos login file. Requires Flyway Teams.
*/
private String kerberosLoginFile;
private @Nullable String kerberosLoginFile;
public String getKerberosLoginFile() {
public @Nullable String getKerberosLoginFile() {
return this.kerberosLoginFile;
}
public void setKerberosLoginFile(String kerberosLoginFile) {
public void setKerberosLoginFile(@Nullable String kerberosLoginFile) {
this.kerberosLoginFile = kerberosLoginFile;
}
@@ -33,6 +33,7 @@ import org.flywaydb.core.api.resource.LoadableResource;
import org.flywaydb.core.internal.resource.classpath.ClassPathResource;
import org.flywaydb.core.internal.scanner.Scanner;
import org.flywaydb.core.internal.util.StringUtils;
import org.jspecify.annotations.Nullable;
import org.springframework.core.NativeDetector;
import org.springframework.core.io.Resource;
@@ -74,7 +75,7 @@ class NativeImageResourceProvider implements ResourceProvider {
}
@Override
public LoadableResource getResource(String name) {
public @Nullable LoadableResource getResource(String name) {
if (!NativeDetector.inNativeImage()) {
return this.scanner.getResource(name);
}
@@ -18,6 +18,8 @@ package org.springframework.boot.flyway.autoconfigure;
import javax.lang.model.element.Modifier;
import org.jspecify.annotations.Nullable;
import org.springframework.aot.generate.GeneratedMethod;
import org.springframework.aot.generate.GenerationContext;
import org.springframework.beans.factory.aot.BeanRegistrationAotContribution;
@@ -37,7 +39,7 @@ import org.springframework.javapoet.CodeBlock;
class ResourceProviderCustomizerBeanRegistrationAotProcessor implements BeanRegistrationAotProcessor {
@Override
public BeanRegistrationAotContribution processAheadOfTime(RegisteredBean registeredBean) {
public @Nullable BeanRegistrationAotContribution processAheadOfTime(RegisteredBean registeredBean) {
if (registeredBean.getBeanClass().equals(ResourceProviderCustomizer.class)) {
return BeanRegistrationAotContribution
.withCustomCodeFragments((codeFragments) -> new AotContribution(codeFragments, registeredBean));
@@ -17,4 +17,7 @@
/**
* Auto-configuration for Flyway endpoint.
*/
@NullMarked
package org.springframework.boot.flyway.autoconfigure.endpoint;
import org.jspecify.annotations.NullMarked;
@@ -17,4 +17,7 @@
/**
* Auto-configuration for Flyway.
*/
@NullMarked
package org.springframework.boot.flyway.autoconfigure;
import org.jspecify.annotations.NullMarked;
@@ -17,4 +17,7 @@
/**
* Support for Docker Compose Flyway service connections.
*/
@NullMarked
package org.springframework.boot.flyway.docker.compose;
import org.jspecify.annotations.NullMarked;
@@ -26,6 +26,7 @@ import java.util.stream.Stream;
import org.flywaydb.core.Flyway;
import org.flywaydb.core.api.MigrationInfo;
import org.flywaydb.core.api.MigrationState;
import org.jspecify.annotations.Nullable;
import org.springframework.boot.actuate.endpoint.OperationResponseBody;
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
@@ -90,9 +91,9 @@ public class FlywayEndpoint {
private final Map<String, FlywayDescriptor> flywayBeans;
private final String parentId;
private final @Nullable String parentId;
private ContextFlywayBeansDescriptor(Map<String, FlywayDescriptor> flywayBeans, String parentId) {
private ContextFlywayBeansDescriptor(Map<String, FlywayDescriptor> flywayBeans, @Nullable String parentId) {
this.flywayBeans = flywayBeans;
this.parentId = parentId;
}
@@ -101,7 +102,7 @@ public class FlywayEndpoint {
return this.flywayBeans;
}
public String getParentId() {
public @Nullable String getParentId() {
return this.parentId;
}
@@ -137,7 +138,7 @@ public class FlywayEndpoint {
private final Integer checksum;
private final String version;
private final @Nullable String version;
private final String description;
@@ -147,7 +148,7 @@ public class FlywayEndpoint {
private final String installedBy;
private final Instant installedOn;
private final @Nullable Instant installedOn;
private final Integer installedRank;
@@ -166,11 +167,11 @@ public class FlywayEndpoint {
this.installedOn = nullSafeToInstant(info.getInstalledOn());
}
private String nullSafeToString(Object obj) {
private @Nullable String nullSafeToString(@Nullable Object obj) {
return (obj != null) ? obj.toString() : null;
}
private Instant nullSafeToInstant(Date date) {
private @Nullable Instant nullSafeToInstant(@Nullable Date date) {
return (date != null) ? Instant.ofEpochMilli(date.getTime()) : null;
}
@@ -182,7 +183,7 @@ public class FlywayEndpoint {
return this.checksum;
}
public String getVersion() {
public @Nullable String getVersion() {
return this.version;
}
@@ -202,7 +203,7 @@ public class FlywayEndpoint {
return this.installedBy;
}
public Instant getInstalledOn() {
public @Nullable Instant getInstalledOn() {
return this.installedOn;
}
@@ -17,4 +17,7 @@
/**
* Actuator endpoint for Flyway.
*/
@NullMarked
package org.springframework.boot.flyway.endpoint;
import org.jspecify.annotations.NullMarked;
@@ -17,4 +17,7 @@
/**
* Custom support for Flyway database migration.
*/
@NullMarked
package org.springframework.boot.flyway;
import org.jspecify.annotations.NullMarked;
@@ -17,4 +17,7 @@
/**
* Support for testcontainers Flyway service connections.
*/
@NullMarked
package org.springframework.boot.flyway.testcontainers;
import org.jspecify.annotations.NullMarked;