flyway: java.lang.IndexOutOfBoundsException: Index 0 out of bounds for length 0 at org.flywaydb.core.internal.configuration.ConfigUtils.(ConfigUtils.java:61)

Which version and edition of Flyway are you using?

flyway open source 10.0.0

Which client are you using? (Command-line, Java API, Maven plugin, Gradle plugin)

Java API on a Kotlin project.

Which database are you using? (Type & version)

Postgresql 16 or 15. It doesn’t matter.

Which operating system are you using?

Ubuntu latest.

What did you do? (Please include the content causing the issue, any relevant configuration settings, the SQL statement(s) that failed (if any), and the command you ran)

It fails in the docker container when trying to load the database to run the migrations.

Gradle configuration:

    implementation("org.flywaydb:flyway-core:10.0.0")
    implementation("org.flywaydb:flyway-database-postgresql:10.0.0")

Connection.

        val flyway = Flyway.configure()
            .driver(DATABASE_DRIVER)
            .dataSource(jdbcUrlString, config[Db.user], config[Db.pass])
            .defaultSchema("public")
            .validateMigrationNaming(true)
            .validateOnMigrate(true)
            .load()

        flyway.baseline()
        flyway.migrate()

It fails on an internal library code.

app  | Exception in thread "main" java.lang.ExceptionInInitializerError
app  | 	at org.flywaydb.core.api.configuration.ClassicConfiguration.configure(ClassicConfiguration.java:1414)
app  | 	at org.flywaydb.core.api.configuration.ClassicConfiguration.configureFromConfigurationProviders(ClassicConfiguration.java:1854)
app  | 	at org.flywaydb.core.api.configuration.ClassicConfiguration.configure(ClassicConfiguration.java:1285)
app  | 	at org.flywaydb.core.api.configuration.ClassicConfiguration.<init>(ClassicConfiguration.java:224)
app  | 	at org.flywaydb.core.Flyway.<init>(Flyway.java:111)
app  | 	at org.flywaydb.core.api.configuration.FluentConfiguration.load(FluentConfiguration.java:59)
app  | 	at .app.infrastructure.database.Database.init(Database.kt:24)
app  | 	at app.ApplicationKt.main(Application.kt:96)
app  | 	at app.ApplicationKt.main(Application.kt)
app  | Caused by: java.lang.IndexOutOfBoundsException: Index 0 out of bounds for length 0
app  | 	at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64)
app  | 	at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:70)
app  | 	at java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:266)
app  | 	at java.base/java.util.Objects.checkIndex(Objects.java:359)
app  | 	at java.base/java.util.ArrayList.get(ArrayList.java:427)
app  | 	at org.flywaydb.core.internal.configuration.ConfigUtils.<clinit>(ConfigUtils.java:61)
app  | 	... 9 more

Docker container from openjdk:17 and application build with gradle 8.4 jdk 17

What did you expect to see?

Migrations running properly.

What did you see instead?

Error on internal flyway library.

About this issue

  • Original URL
  • State: closed
  • Created 8 months ago
  • Comments: 20 (1 by maintainers)

Commits related to this issue

Most upvoted comments

This issue fix will be included in the next release of Flyway.

We had the same error, seems to be related to service definition META-INF files, as @attiand mentioned.

For us adding

tasks.withType<ShadowJar> {
    mergeServiceFiles()
}

to our build.gradle.kts fixed the issue

We had both flyway-core and flyway-database-postgres as direct dependencies

We have the folllowing depedency in a pure java-maven project creating a runnable jar with maven-assembly-plugin:

<dependency>
    <groupId>org.flywaydb</groupId>
    <artifactId>flyway-database-postgresql</artifactId>
    <version>10.0.1</version>
</dependency>

The problem is that both flyway-database-postgresql and flyway-core has a service loader file with the same name (META-INF/services/org.flywaydb.core.extensibility.Plugin). Only the one in flyway-core includes LicensingConfigurationExtensionStub.

The maven-assembly-plugin only adds one of the files. In our case only the one from flyway-database-postgresql was included (which does not include LicensingConfigurationExtensionStub)

The application runs fine from the IDE. But with the runnable-jar we get the problem described above.

We ended up changing to maven-shade-plugin with org.apache.maven.plugins.shade.resource.ManifestResourceTransformer to get all services in place.

We are currently using flyway version 9.22.3 without any problems in my project. When upgrading to 10.0.0 or 10.0.1 we get the same error as @AlejandroYuste .

Hi @attiand , thanks to your detailed description, I can locally reproduce this issue now.

This is in a Kotlin environment

Same here. Working fine with 9.22.3, but getting the error above when upgrading