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

Comparison method violates its general contract! #645

Open
1 task done
GianfrancoMS opened this issue Nov 2, 2022 · 8 comments
Open
1 task done

Comparison method violates its general contract! #645

GianfrancoMS opened this issue Nov 2, 2022 · 8 comments
Assignees

Comments

@GianfrancoMS
Copy link

GianfrancoMS commented Nov 2, 2022

🐛 Describe the bug

When i run, ./gradlew refreshVersions, it throws this exception:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':refreshVersions'.
> Comparison method violates its general contract!

Caused by: java.lang.IllegalArgumentException: Comparison method violates its general contract!
        at kotlin.collections.ArraysKt___ArraysJvmKt.sort(_ArraysJvm.kt:2400)
        at kotlin.collections.CollectionsKt___CollectionsKt.sorted(_Collections.kt:1030)
        at de.fayard.refreshVersions.core.internal.GettingVersionCandidatesKt.sortWith(GettingVersionCandidates.kt:30)
        at de.fayard.refreshVersions.core.internal.GettingVersionCandidatesKt.getVersionCandidates(GettingVersionCandidates.kt:16)
        at de.fayard.refreshVersions.core.internal.GettingVersionCandidatesKt$getVersionCandidates$1.invokeSuspend(GettingVersionCandidates.kt)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
        at kotlinx.coroutines.EventLoopImplBase.processNextEvent(EventLoop.common.kt:279)
        at kotlinx.coroutines.BlockingCoroutine.joinBlocking(Builders.kt:85)
        at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking(Builders.kt:59)
        at kotlinx.coroutines.BuildersKt.runBlocking(Unknown Source)
        at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking$default(Builders.kt:38)
        at kotlinx.coroutines.BuildersKt.runBlocking$default(Unknown Source)
        at de.fayard.refreshVersions.core.RefreshVersionsTask.taskActionRefreshVersions(RefreshVersionsTask.kt:74)

I manage my dependencies using a TOML file at gradle/libs.versions.toml
I'm using version 0.51.0

⚠️ Current behavior

It does not work in my project.

✅ Expected behavior

It should work without exceptions.

💣 Steps to reproduce

📱 Tech info

Unfortunately, I can't provide a build scan due to privacy reasons from my company.

@LouisCAD
Copy link
Member

Hello, can you try to provide us which dependencies are triggering this issue?
If you want, you can send me the list via email for privacy, you can find it on my GitHub profile.

@mcpiroman
Copy link

This started popping up for me as well, my current setup is:

libs.versions.toml:

## Generated by $ ./gradlew refreshVersionsCatalog

[plugins]

kotlin = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
org-beryx-runtime = { id = "org.beryx.runtime", version = "1.13.0" }

[versions]

kotlin = "1.8.20-dev-5197"
kotlinx-coroutines = "1.6.4"
skiko = "0.7.44"

[libraries]

kotlinx-collections-immutable = { module = "org.jetbrains.kotlinx:kotlinx-collections-immutable", version = "0.3.5" }
skiko = { module = "org.jetbrains.skiko:skiko", version.ref = "skiko" }
jdom2 = { module = "org.jdom:jdom2", version = "2.0.6.1" }
unbescape = { module = "org.unbescape:unbescape", version = "1.1.6.RELEASE" }
slf4j-nop = { module = "org.slf4j:slf4j-nop", version = "1.7.36" }
classpath = { module = "io.github.classgraph:classgraph", version = "4.8.153" }

settings.gradle.kts:

pluginManagement {
    repositories {
        gradlePluginPortal()
        maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/bootstrap")
    }
}

plugins {
    id("de.fayard.refreshVersions") version "0.51.0"
}

refreshVersions {
    rejectVersionIf {
        moduleId.group in listOf("org.slf4j")
    }
}

include(...)

@borsini
Copy link
Contributor

borsini commented Apr 5, 2023

🖖 Hi!
@RobinMaronier and I stumbled across this exact same issue as well when migrating from properties file to version catalog.
What could we do to help narrowing down the problem?

@LouisCAD LouisCAD self-assigned this Apr 6, 2023
@mpetuska
Copy link

Encountered the same issue myself. Here's a build scan

The code from the build is here

Hope this helps!

@LouisCAD
Copy link
Member

LouisCAD commented Feb 7, 2024

If you know which dependency is causing this issue, that would be helpful.

I don't have much time to dive into that issue, which I never reproduced on my own projects, but happy to get further help.

@cleberhenriques
Copy link

@LouisCAD I was running into the same problem and I believe I managed to determine which dependency is causing the issue: detekt. At least in my case and probably @mpetuska case.

The issue started happening after I fixed a version mismatch between the plugin io.gitlab.arturbosch.detekt and the dependency io.gitlab.arturbosch.detekt:detekt-formatting

After I set up both dependencies to use the same version, refreshVersions stopped working with the following error:

Execution failed for task ':refreshVersions'.
> Comparison method violates its general contract!

I reverted the changes and it worked again. It doesn't matter which version is used, if they're the same, it fails.

I had a look at the example project/commit that @mpetuska shared and it's also using the detekt plugin + detekt-formatting dependency.

If I have enough time I will try to create an example project.

@LouisCAD
Copy link
Member

Thank you for pinpointing the involved dependencies!
Can you specify the versions where you have no issues, and the version where you have it?

A copy of the part from the versions.properties file will do.

No need for a reproducer anymore now.

@cleberhenriques
Copy link

cleberhenriques commented Apr 2, 2024

@LouisCAD

After investigating a bit more time I came to the conclusion that it's not the version mismatch per-se... In my case, just having the detektFormatting = {module = "io.gitlab.arturbosch.detekt:detekt-formatting", version.ref = "detekt"} in the libs.versions.toml is enough to force the error.

I created an example project trying to mimic the same setup I have at work in case you're interested.

Here's a diff between the failing commit and the working commit: cleberhenriques/ref-ver-detekt-error@26b02ef

Also, a buildScan: https://scans.gradle.com/s/khyecc7pdgmhm/failure?expanded-stacktrace=WyIwLTEiXQ#1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants