Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MigrationInfoImpl violates the compareTo contract #1249

mrjeffjohnston opened this issue Mar 21, 2016 · 3 comments

MigrationInfoImpl violates the compareTo contract #1249

mrjeffjohnston opened this issue Mar 21, 2016 · 3 comments


Copy link

@mrjeffjohnston mrjeffjohnston commented Mar 21, 2016

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?


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(
at java.util.TimSort.mergeAt(
at java.util.TimSort.mergeCollapse(
at java.util.TimSort.sort(
at java.util.TimSort.sort(
at java.util.Arrays.sort(
at java.util.Collections.sort(

@axelfontaine axelfontaine added this to the Flyway 4.0.1 milestone Mar 21, 2016
Copy link

@geirwr geirwr commented Mar 29, 2016

+1 vote

using Oracle 12c (
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(
        at java.util.ComparableTimSort.mergeAt(
        at java.util.ComparableTimSort.mergeCollapse(
        at java.util.ComparableTimSort.sort(
        at java.util.Arrays.sort(
        at java.util.Arrays.sort(
        at java.util.ArrayList.sort(
        at java.util.Collections.sort(

Copy link

@nupa nupa commented Apr 20, 2016

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?

Copy link

@ennru ennru commented Apr 27, 2016

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

5 participants
You can’t perform that action at this time.