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.
4.0
SQL Server 2012
Windows XP
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.
That the new repeatable migrations would be applied.
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)
+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.