Skip to content

Commit eb31180

Browse files
committed
Add nullability annotations to module/spring-boot-flyway
See gh-46587
1 parent 5ac6dfc commit eb31180

File tree

13 files changed

+128
-100
lines changed

13 files changed

+128
-100
lines changed

module/spring-boot-flyway/src/main/java/org/springframework/boot/flyway/autoconfigure/FlywayAutoConfiguration.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import org.flywaydb.database.oracle.OracleConfigurationExtension;
3939
import org.flywaydb.database.postgresql.PostgreSQLConfigurationExtension;
4040
import org.flywaydb.database.sqlserver.SQLServerConfigurationExtension;
41+
import org.jspecify.annotations.Nullable;
4142

4243
import org.springframework.aot.hint.RuntimeHints;
4344
import org.springframework.aot.hint.RuntimeHintsRegistrar;
@@ -177,14 +178,14 @@ Flyway flyway(FlywayConnectionDetails connectionDetails, ResourceLoader resource
177178
return configuration.load();
178179
}
179180

180-
private void configureDataSource(FluentConfiguration configuration, DataSource flywayDataSource,
181-
DataSource dataSource, FlywayConnectionDetails connectionDetails) {
181+
private void configureDataSource(FluentConfiguration configuration, @Nullable DataSource flywayDataSource,
182+
@Nullable DataSource dataSource, FlywayConnectionDetails connectionDetails) {
182183
DataSource migrationDataSource = getMigrationDataSource(flywayDataSource, dataSource, connectionDetails);
183184
configuration.dataSource(migrationDataSource);
184185
}
185186

186-
private DataSource getMigrationDataSource(DataSource flywayDataSource, DataSource dataSource,
187-
FlywayConnectionDetails connectionDetails) {
187+
private DataSource getMigrationDataSource(@Nullable DataSource flywayDataSource,
188+
@Nullable DataSource dataSource, FlywayConnectionDetails connectionDetails) {
188189
if (flywayDataSource != null) {
189190
return flywayDataSource;
190191
}
@@ -424,7 +425,7 @@ public Set<ConvertiblePair> getConvertibleTypes() {
424425
}
425426

426427
@Override
427-
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
428+
public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
428429
String value = ObjectUtils.nullSafeToString(source);
429430
return MigrationVersion.fromVersion(value);
430431
}
@@ -457,7 +458,7 @@ private static final class FlywayUrlCondition {
457458
static class FlywayAutoConfigurationRuntimeHints implements RuntimeHintsRegistrar {
458459

459460
@Override
460-
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
461+
public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) {
461462
hints.resources().registerPattern("db/migration/*");
462463
}
463464

@@ -475,22 +476,22 @@ static final class PropertiesFlywayConnectionDetails implements FlywayConnection
475476
}
476477

477478
@Override
478-
public String getUsername() {
479+
public @Nullable String getUsername() {
479480
return this.properties.getUser();
480481
}
481482

482483
@Override
483-
public String getPassword() {
484+
public @Nullable String getPassword() {
484485
return this.properties.getPassword();
485486
}
486487

487488
@Override
488-
public String getJdbcUrl() {
489+
public @Nullable String getJdbcUrl() {
489490
return this.properties.getUrl();
490491
}
491492

492493
@Override
493-
public String getDriverClassName() {
494+
public @Nullable String getDriverClassName() {
494495
return this.properties.getDriverClassName();
495496
}
496497

@@ -574,7 +575,7 @@ private void setKerberosLoginFile(SQLServerConfigurationExtension configuration,
574575
*/
575576
static class Extension<E extends ConfigurationExtension> {
576577

577-
private SingletonSupplier<E> extension;
578+
private final SingletonSupplier<E> extension;
578579

579580
Extension(FluentConfiguration configuration, Class<E> type, String name) {
580581
this.extension = SingletonSupplier.of(() -> {

module/spring-boot-flyway/src/main/java/org/springframework/boot/flyway/autoconfigure/FlywayConnectionDetails.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package org.springframework.boot.flyway.autoconfigure;
1818

19+
import org.jspecify.annotations.Nullable;
20+
1921
import org.springframework.boot.autoconfigure.service.connection.ConnectionDetails;
2022
import org.springframework.boot.jdbc.DatabaseDriver;
2123

@@ -32,21 +34,21 @@ public interface FlywayConnectionDetails extends ConnectionDetails {
3234
* required.
3335
* @return the username for the database or {@code null}
3436
*/
35-
String getUsername();
37+
@Nullable String getUsername();
3638

3739
/**
3840
* Password for the database or {@code null} if no Flyway-specific configuration is
3941
* required.
4042
* @return the password for the database or {@code null}
4143
*/
42-
String getPassword();
44+
@Nullable String getPassword();
4345

4446
/**
4547
* JDBC URL for the database or {@code null} if no Flyway-specific configuration is
4648
* required.
4749
* @return the JDBC URL for the database or {@code null}
4850
*/
49-
String getJdbcUrl();
51+
@Nullable String getJdbcUrl();
5052

5153
/**
5254
* The name of the JDBC driver class. Defaults to the class name of the driver
@@ -56,7 +58,7 @@ public interface FlywayConnectionDetails extends ConnectionDetails {
5658
* @see DatabaseDriver#fromJdbcUrl(String)
5759
* @see DatabaseDriver#getDriverClassName()
5860
*/
59-
default String getDriverClassName() {
61+
default @Nullable String getDriverClassName() {
6062
String jdbcUrl = getJdbcUrl();
6163
return (jdbcUrl != null) ? DatabaseDriver.fromJdbcUrl(jdbcUrl).getDriverClassName() : null;
6264
}

module/spring-boot-flyway/src/main/java/org/springframework/boot/flyway/autoconfigure/FlywayMigrationInitializer.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.springframework.boot.flyway.autoconfigure;
1818

1919
import org.flywaydb.core.Flyway;
20+
import org.jspecify.annotations.Nullable;
2021

2122
import org.springframework.beans.factory.InitializingBean;
2223
import org.springframework.core.Ordered;
@@ -33,7 +34,7 @@ public class FlywayMigrationInitializer implements InitializingBean, Ordered {
3334

3435
private final Flyway flyway;
3536

36-
private final FlywayMigrationStrategy migrationStrategy;
37+
private final @Nullable FlywayMigrationStrategy migrationStrategy;
3738

3839
private int order = 0;
3940

@@ -50,7 +51,7 @@ public FlywayMigrationInitializer(Flyway flyway) {
5051
* @param flyway the flyway instance
5152
* @param migrationStrategy the migration strategy or {@code null}
5253
*/
53-
public FlywayMigrationInitializer(Flyway flyway, FlywayMigrationStrategy migrationStrategy) {
54+
public FlywayMigrationInitializer(Flyway flyway, @Nullable FlywayMigrationStrategy migrationStrategy) {
5455
Assert.notNull(flyway, "'flyway' must not be null");
5556
this.flyway = flyway;
5657
this.migrationStrategy = migrationStrategy;

0 commit comments

Comments
 (0)