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

Closed
mrjeffjohnston opened this issue Mar 21, 2016 · 3 comments
Closed

MigrationInfoImpl violates the compareTo contract #1249

mrjeffjohnston opened this issue Mar 21, 2016 · 3 comments
Labels
Milestone

Comments

@mrjeffjohnston
Copy link
Contributor

@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?

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)

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

@geirwr geirwr commented Mar 29, 2016

+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)

@nupa
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?

@ennru
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
Projects
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.