Flyway: MigrationInfoImpl violates the compareTo contract

Created on 21 Mar 2016  路  3Comments  路  Source: flyway/flyway

MigrationInfoImpl compareTo violates the required contract for repeatable migrations, i.e. those with a null version.

Migration 1: R__C.sql is applied - installed rank is 5
Migration 2: R__A.sql is applied - installed rank is 10

For migration 3 there is a new repeatable migration, R__B.sql. If these 3 objects are compared in MigrationInfoImpl.compareTo then:
R__C.sql < R__A.sql (Due to installed rank)
R__B.sql < R__C.sql (Due to alphabetical order)
R__A.sql < R__B.sql (Due to alphabetical order)

This is logically impossible and causes the sort method to throw an exception. But not reliably, it depends on the internal workings of the sort method.

What version of Flyway are you using?

4.0

What database are you using (type & version)?

SQL Server 2012

What operating system are you using?

Windows XP

What did you do?

I have some normal migrations and a bunch of repeatable migrations. The defect occurs when there are existing applied repeatable migrations and some new repeatable migrations.

What did you expect to see?

That the new repeatable migrations would be applied.

What did you see instead?

Exception from sorting collection of MigrationInfoImpl
java.lang.IllegalArgumentException: Comparison method violates its general contract!
at java.util.TimSort.mergeLo(TimSort.java:747)
at java.util.TimSort.mergeAt(TimSort.java:483)
at java.util.TimSort.mergeCollapse(TimSort.java:410)
at java.util.TimSort.sort(TimSort.java:214)
at java.util.TimSort.sort(TimSort.java:173)
at java.util.Arrays.sort(Arrays.java:659)
at java.util.Collections.sort(Collections.java:217)

Core bug

All 3 comments

+1 vote

using Oracle 12c (12.1.0.2.0)
flyway 4.0
Java version: 1.8.0_74

Caused by: java.lang.IllegalArgumentException: Comparison method violates its general contract!
        at java.util.ComparableTimSort.mergeLo(ComparableTimSort.java:744)
        at java.util.ComparableTimSort.mergeAt(ComparableTimSort.java:481)
        at java.util.ComparableTimSort.mergeCollapse(ComparableTimSort.java:406)
        at java.util.ComparableTimSort.sort(ComparableTimSort.java:213)
        at java.util.Arrays.sort(Arrays.java:1312)
        at java.util.Arrays.sort(Arrays.java:1506)
        at java.util.ArrayList.sort(ArrayList.java:1454)
        at java.util.Collections.sort(Collections.java:141)
        at org.flywaydb.core.internal.info.MigrationInfoServiceImpl.mergeAvailableAndAppliedMigrations(MigrationInfoServiceImpl.java:201)
        at org.flywaydb.core.internal.info.MigrationInfoServiceImpl.refresh(MigrationInfoServiceImpl.java:107)

Should outOfOrder() in FlywayMediumTest be fixed too, as now the pending migrations come after the installed ones? So the assertion for PENDING status now points to wrong item in the array?

We built from master with Axel's fix and it solved the problems we had in our environment.
Thank you! Would be good to see a 4.0.1 fix release soon as this is a very serious bug.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

berlin-ab picture berlin-ab  路  3Comments

terje2001 picture terje2001  路  3Comments

expeditioneer picture expeditioneer  路  4Comments

pupeno picture pupeno  路  4Comments

flyway picture flyway  路  4Comments