Skip to content

Conversation

@wadimw
Copy link

@wadimw wadimw commented Dec 19, 2025

Conditional check for tryToMigrateIfMysql8Migration throws NPE when run against a Spring Boot 1 database:

Caused by: java.lang.NullPointerException: Cannot invoke "org.flywaydb.core.api.MigrationInfo.getVersion()" because the return value of "org.flywaydb.core.api.MigrationInfoService.current()" is null
	at com.box.l10n.mojito.FlyWayConfig.lambda$0(FlyWayConfig.java:50)
	at org.springframework.boot.autoconfigure.flyway.FlywayMigrationInitializer.afterPropertiesSet(FlywayMigrationInitializer.java:62)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1815)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1764)
	... 16 common frames omitted

even though the first thrown FlywayException should actually be handled by tryToMigrateIfSpringMigration:

org.flywaydb.core.api.FlywayException: Found non-empty schema(s) `mojito` but no schema history table. Use baseline() or set baselineOnMigrate to true to initialize the schema history table.
	at org.flywaydb.core.Flyway.lambda$migrate$0(Flyway.java:178)
	at org.flywaydb.core.FlywayExecutor.execute(FlywayExecutor.java:196)
	at org.flywaydb.core.Flyway.migrate(Flyway.java:140)
	at com.box.l10n.mojito.FlyWayConfig.lambda$0(FlyWayConfig.java:46)
	at org.springframework.boot.autoconfigure.flyway.FlywayMigrationInitializer.afterPropertiesSet(FlywayMigrationInitializer.java:62)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1815)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1764)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:596)

This commit:

  • changes order of migration attempts (SpringMigration first)
  • changes conditional MySQL8 migration to first check exception text, then attempt to retrieve schema version

Conditional check for `tryToMigrateIfMysql8Migration` throws NPE when run against a Spring Boot 1 database:

```log
Caused by: java.lang.NullPointerException: Cannot invoke "org.flywaydb.core.api.MigrationInfo.getVersion()" because the return value of "org.flywaydb.core.api.MigrationInfoService.current()" is null
	at com.box.l10n.mojito.FlyWayConfig.lambda$0(FlyWayConfig.java:50)
	at org.springframework.boot.autoconfigure.flyway.FlywayMigrationInitializer.afterPropertiesSet(FlywayMigrationInitializer.java:62)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1815)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1764)
	... 16 common frames omitted
```

even though the first thrown `FlywayException` should actually be handled by `tryToMigrateIfSpringMigration`:

```log
org.flywaydb.core.api.FlywayException: Found non-empty schema(s) `mojito` but no schema history table. Use baseline() or set baselineOnMigrate to true to initialize the schema history table.
	at org.flywaydb.core.Flyway.lambda$migrate$0(Flyway.java:178)
	at org.flywaydb.core.FlywayExecutor.execute(FlywayExecutor.java:196)
	at org.flywaydb.core.Flyway.migrate(Flyway.java:140)
	at com.box.l10n.mojito.FlyWayConfig.lambda$0(FlyWayConfig.java:46)
	at org.springframework.boot.autoconfigure.flyway.FlywayMigrationInitializer.afterPropertiesSet(FlywayMigrationInitializer.java:62)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1815)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1764)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:596)
```

This commit:
* changes order of migration attempts (SpringMigration first)
* changes conditional MySQL8 migration to first check exception text, then attempt to retrieve schema version
@wadimw wadimw added the upstream-patched Experimental features ported from legacy branch label Dec 19, 2025
@wadimw wadimw merged commit 40188ba into upstream-patched Dec 22, 2025
4 checks passed
@wadimw wadimw deleted the fix-flyway branch December 22, 2025 07:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

upstream-patched Experimental features ported from legacy branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants