Skip to content

Commit 51ec3ce

Browse files
committed
Add nullability annotations to module/spring-boot-liquibase
See gh-46587
1 parent 97ad5cb commit 51ec3ce

File tree

12 files changed

+104
-76
lines changed

12 files changed

+104
-76
lines changed

module/spring-boot-liquibase/src/main/java/org/springframework/boot/liquibase/LiquibaseChangelogMissingFailureAnalyzer.java

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

1919
import liquibase.exception.ChangeLogParseException;
20+
import org.jspecify.annotations.Nullable;
2021

2122
import org.springframework.boot.diagnostics.AbstractFailureAnalyzer;
2223
import org.springframework.boot.diagnostics.FailureAnalysis;
@@ -32,17 +33,18 @@ class LiquibaseChangelogMissingFailureAnalyzer extends AbstractFailureAnalyzer<C
3233
private static final String MESSAGE_SUFFIX = " does not exist";
3334

3435
@Override
35-
protected FailureAnalysis analyze(Throwable rootFailure, ChangeLogParseException cause) {
36-
if (cause.getMessage().endsWith(MESSAGE_SUFFIX)) {
37-
String changelogPath = extractChangelogPath(cause);
36+
protected @Nullable FailureAnalysis analyze(Throwable rootFailure, ChangeLogParseException cause) {
37+
String message = cause.getMessage();
38+
if (message != null && message.endsWith(MESSAGE_SUFFIX)) {
39+
String changelogPath = extractChangelogPath(message);
3840
return new FailureAnalysis(getDescription(changelogPath),
3941
"Make sure a Liquibase changelog is present at the configured path.", cause);
4042
}
4143
return null;
4244
}
4345

44-
private String extractChangelogPath(ChangeLogParseException cause) {
45-
return cause.getMessage().substring(0, cause.getMessage().length() - MESSAGE_SUFFIX.length());
46+
private String extractChangelogPath(String message) {
47+
return message.substring(0, message.length() - MESSAGE_SUFFIX.length());
4648
}
4749

4850
private String getDescription(String changelogPath) {

module/spring-boot-liquibase/src/main/java/org/springframework/boot/liquibase/autoconfigure/LiquibaseAutoConfiguration.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import liquibase.integration.spring.Customizer;
2626
import liquibase.integration.spring.SpringLiquibase;
2727
import liquibase.ui.UIServiceEnum;
28+
import org.jspecify.annotations.Nullable;
2829

2930
import org.springframework.aot.hint.RuntimeHints;
3031
import org.springframework.aot.hint.RuntimeHintsRegistrar;
@@ -142,8 +143,8 @@ SpringLiquibase liquibase(ObjectProvider<DataSource> dataSource,
142143
return liquibase;
143144
}
144145

145-
private SpringLiquibase createSpringLiquibase(DataSource liquibaseDataSource, DataSource dataSource,
146-
LiquibaseConnectionDetails connectionDetails) {
146+
private SpringLiquibase createSpringLiquibase(@Nullable DataSource liquibaseDataSource,
147+
@Nullable DataSource dataSource, LiquibaseConnectionDetails connectionDetails) {
147148
DataSource migrationDataSource = getMigrationDataSource(liquibaseDataSource, dataSource, connectionDetails);
148149
SpringLiquibase liquibase = (migrationDataSource == liquibaseDataSource
149150
|| migrationDataSource == dataSource) ? new SpringLiquibase()
@@ -152,8 +153,8 @@ private SpringLiquibase createSpringLiquibase(DataSource liquibaseDataSource, Da
152153
return liquibase;
153154
}
154155

155-
private DataSource getMigrationDataSource(DataSource liquibaseDataSource, DataSource dataSource,
156-
LiquibaseConnectionDetails connectionDetails) {
156+
private DataSource getMigrationDataSource(@Nullable DataSource liquibaseDataSource,
157+
@Nullable DataSource dataSource, LiquibaseConnectionDetails connectionDetails) {
157158
if (liquibaseDataSource != null) {
158159
return liquibaseDataSource;
159160
}
@@ -224,7 +225,7 @@ private static final class LiquibaseUrlCondition {
224225
static class LiquibaseAutoConfigurationRuntimeHints implements RuntimeHintsRegistrar {
225226

226227
@Override
227-
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
228+
public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) {
228229
hints.resources().registerPattern("db/changelog/**");
229230
}
230231

@@ -242,22 +243,22 @@ static final class PropertiesLiquibaseConnectionDetails implements LiquibaseConn
242243
}
243244

244245
@Override
245-
public String getUsername() {
246+
public @Nullable String getUsername() {
246247
return this.properties.getUser();
247248
}
248249

249250
@Override
250-
public String getPassword() {
251+
public @Nullable String getPassword() {
251252
return this.properties.getPassword();
252253
}
253254

254255
@Override
255-
public String getJdbcUrl() {
256+
public @Nullable String getJdbcUrl() {
256257
return this.properties.getUrl();
257258
}
258259

259260
@Override
260-
public String getDriverClassName() {
261+
public @Nullable String getDriverClassName() {
261262
String driverClassName = this.properties.getDriverClassName();
262263
return (driverClassName != null) ? driverClassName : LiquibaseConnectionDetails.super.getDriverClassName();
263264
}

module/spring-boot-liquibase/src/main/java/org/springframework/boot/liquibase/autoconfigure/LiquibaseConnectionDetails.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.liquibase.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 LiquibaseConnectionDetails 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 Liquibase-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 Liquibase-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 LiquibaseConnectionDetails extends ConnectionDetails {
5658
* @see DatabaseDriver#fromJdbcUrl(String)
5759
* @see DatabaseDriver#getDriverClassName()
5860
*/
59-
default String getDriverClassName() {
61+
@Nullable default String getDriverClassName() {
6062
String jdbcUrl = getJdbcUrl();
6163
return (jdbcUrl != null) ? DatabaseDriver.fromJdbcUrl(jdbcUrl).getDriverClassName() : null;
6264
}

0 commit comments

Comments
 (0)