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

mvn versions:display-dependency-updates throws llegalArgumentException: Comparison method violates its general contract! #1147

Open
RalfNaujokat opened this issue Sep 23, 2024 · 9 comments
Assignees

Comments

@RalfNaujokat
Copy link

RalfNaujokat commented Sep 23, 2024

Using Maven 3.9.9 with different JDKs (Oracle Java 21, GraalVM 21/23) on Linux

StackTrace is:

`
== BEGIN ==

[ERROR] Failed to execute goal org.codehaus.mojo:versions-maven-plugin:2.17.1:display-dependency-updates (default-cli) on project libraries: Unable to acquire metadata for dependencies java.util.stream.ReferencePipeline$2@629591d0: java.lang.IllegalArgumentException: Comparison method violates its general contract! -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.codehaus.mojo:versions-maven-plugin:2.17.1:display-dependency-updates (default-cli) on project libraries: Unable to acquire metadata for dependencies java.util.stream.ReferencePipeline$2@629591d0: java.lang.IllegalArgumentException: Comparison method violates its general contract!
at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:333)
at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:316)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:212)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:174)
at org.apache.maven.lifecycle.internal.MojoExecutor.access$000 (MojoExecutor.java:75)
at org.apache.maven.lifecycle.internal.MojoExecutor$1.run (MojoExecutor.java:162)
at org.apache.maven.plugin.DefaultMojosExecutionStrategy.execute (DefaultMojosExecutionStrategy.java:39)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:159)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:105)
at org.apache.maven.lifecycle.internal.builder.multithreaded.MultiThreadedBuilder$1.call (MultiThreadedBuilder.java:193)
at org.apache.maven.lifecycle.internal.builder.multithreaded.MultiThreadedBuilder$1.call (MultiThreadedBuilder.java:180)
at java.util.concurrent.FutureTask.run (FutureTask.java:317)
at java.util.concurrent.Executors$RunnableAdapter.call (Executors.java:572)
at java.util.concurrent.FutureTask.run (FutureTask.java:317)
at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1144)
at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:642)
at java.lang.Thread.run (Thread.java:1583)
Caused by: org.apache.maven.plugin.MojoExecutionException: Unable to acquire metadata for dependencies java.util.stream.ReferencePipeline$2@629591d0: java.lang.IllegalArgumentException: Comparison method violates its general contract!
at org.codehaus.mojo.versions.DisplayDependencyUpdatesMojo.execute (DisplayDependencyUpdatesMojo.java:477)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:126)
at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:328)
at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:316)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:212)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:174)
at org.apache.maven.lifecycle.internal.MojoExecutor.access$000 (MojoExecutor.java:75)
at org.apache.maven.lifecycle.internal.MojoExecutor$1.run (MojoExecutor.java:162)
at org.apache.maven.plugin.DefaultMojosExecutionStrategy.execute (DefaultMojosExecutionStrategy.java:39)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:159)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:105)
at org.apache.maven.lifecycle.internal.builder.multithreaded.MultiThreadedBuilder$1.call (MultiThreadedBuilder.java:193)
at org.apache.maven.lifecycle.internal.builder.multithreaded.MultiThreadedBuilder$1.call (MultiThreadedBuilder.java:180)
at java.util.concurrent.FutureTask.run (FutureTask.java:317)
at java.util.concurrent.Executors$RunnableAdapter.call (Executors.java:572)
at java.util.concurrent.FutureTask.run (FutureTask.java:317)
at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1144)
at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:642)
at java.lang.Thread.run (Thread.java:1583)
Caused by: org.codehaus.mojo.versions.api.VersionRetrievalException: Unable to acquire metadata for dependencies java.util.stream.ReferencePipeline$2@629591d0: java.lang.IllegalArgumentException: Comparison method violates its general contract!
at org.codehaus.mojo.versions.api.DefaultVersionsHelper.lookupDependenciesUpdates (DefaultVersionsHelper.java:533)
at org.codehaus.mojo.versions.api.DefaultVersionsHelper.lookupDependenciesUpdates (DefaultVersionsHelper.java:543)
at org.codehaus.mojo.versions.DisplayDependencyUpdatesMojo.execute (DisplayDependencyUpdatesMojo.java:412)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:126)
at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:328)
at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:316)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:212)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:174)
at org.apache.maven.lifecycle.internal.MojoExecutor.access$000 (MojoExecutor.java:75)
at org.apache.maven.lifecycle.internal.MojoExecutor$1.run (MojoExecutor.java:162)
at org.apache.maven.plugin.DefaultMojosExecutionStrategy.execute (DefaultMojosExecutionStrategy.java:39)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:159)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:105)
at org.apache.maven.lifecycle.internal.builder.multithreaded.MultiThreadedBuilder$1.call (MultiThreadedBuilder.java:193)
at org.apache.maven.lifecycle.internal.builder.multithreaded.MultiThreadedBuilder$1.call (MultiThreadedBuilder.java:180)
at java.util.concurrent.FutureTask.run (FutureTask.java:317)
at java.util.concurrent.Executors$RunnableAdapter.call (Executors.java:572)
at java.util.concurrent.FutureTask.run (FutureTask.java:317)
at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1144)
at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:642)
at java.lang.Thread.run (Thread.java:1583)
Caused by: java.util.concurrent.ExecutionException: java.lang.IllegalArgumentException: Comparison method violates its general contract!
at java.util.concurrent.FutureTask.report (FutureTask.java:122)
at java.util.concurrent.FutureTask.get (FutureTask.java:191)
at org.codehaus.mojo.versions.api.DefaultVersionsHelper.lookupDependenciesUpdates (DefaultVersionsHelper.java:526)
at org.codehaus.mojo.versions.api.DefaultVersionsHelper.lookupDependenciesUpdates (DefaultVersionsHelper.java:543)
at org.codehaus.mojo.versions.DisplayDependencyUpdatesMojo.execute (DisplayDependencyUpdatesMojo.java:412)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:126)
at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:328)
at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:316)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:212)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:174)
at org.apache.maven.lifecycle.internal.MojoExecutor.access$000 (MojoExecutor.java:75)
at org.apache.maven.lifecycle.internal.MojoExecutor$1.run (MojoExecutor.java:162)
at org.apache.maven.plugin.DefaultMojosExecutionStrategy.execute (DefaultMojosExecutionStrategy.java:39)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:159)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:105)
at org.apache.maven.lifecycle.internal.builder.multithreaded.MultiThreadedBuilder$1.call (MultiThreadedBuilder.java:193)
at org.apache.maven.lifecycle.internal.builder.multithreaded.MultiThreadedBuilder$1.call (MultiThreadedBuilder.java:180)
at java.util.concurrent.FutureTask.run (FutureTask.java:317)
at java.util.concurrent.Executors$RunnableAdapter.call (Executors.java:572)
at java.util.concurrent.FutureTask.run (FutureTask.java:317)
at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1144)
at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:642)
at java.lang.Thread.run (Thread.java:1583)
Caused by: java.lang.IllegalArgumentException: Comparison method violates its general contract!
at java.util.ComparableTimSort.mergeHi (ComparableTimSort.java:870)
at java.util.ComparableTimSort.mergeAt (ComparableTimSort.java:487)
at java.util.ComparableTimSort.mergeForceCollapse (ComparableTimSort.java:426)
at java.util.ComparableTimSort.sort (ComparableTimSort.java:222)
at java.util.Arrays.sort (Arrays.java:1108)
at java.util.Arrays.sort (Arrays.java:1302)
at java.util.ArrayList.sort (ArrayList.java:1804)
at java.util.Collections.sort (Collections.java:145)
at org.apache.maven.repository.internal.DefaultVersionRangeResolver.resolveVersionRange (DefaultVersionRangeResolver.java:160)
at org.eclipse.aether.internal.impl.DefaultRepositorySystem.resolveVersionRange (DefaultRepositorySystem.java:260)
at org.codehaus.mojo.versions.api.DefaultVersionsHelper.lookupArtifactVersions (DefaultVersionsHelper.java:282)
at org.codehaus.mojo.versions.api.DefaultVersionsHelper.lookupDependencyUpdates (DefaultVersionsHelper.java:553)
at org.codehaus.mojo.versions.api.DefaultVersionsHelper.lambda$lookupDependenciesUpdates$4 (DefaultVersionsHelper.java:522)
at java.util.concurrent.FutureTask.run (FutureTask.java:317)
at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1144)
at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:642)
at java.lang.Thread.run (Thread.java:1583)

== END ==
`

@RalfNaujokat
Copy link
Author

Google took me to:
https://stackoverflow.com/questions/71027480/java-exception-exception-java-lang-illegalargumentexception-comparison-method

and then to
https://stackoverflow.com/questions/8327514/comparison-method-violates-its-general-contract

so finally starting as
export MAVEN_OPTS="-Djava.util.Arrays.useLegacyMergeSort=true" ; mvn versions:display-dependency-updates

at least is a workaround.

@andrzejj0
Copy link
Contributor

Can you provide a minimal project (pom.xml) to run the goal on in order to reproduce the problem?

@RalfNaujokat
Copy link
Author

sorry, but i this happened only on one very big project with tons of dependencies.
i have no clue which one triggers the error.

@andrzejj0
Copy link
Contributor

Does this happen with other Maven versions on this particular project?

@andrzejj0 andrzejj0 self-assigned this Oct 19, 2024
@andrzejj0 andrzejj0 added the bug label Oct 19, 2024
@andrzejj0
Copy link
Contributor

andrzejj0 commented Oct 19, 2024

Looking at the stack trace, it seems that it's an error within Resolver (so, Maven) rather than in the plugin itself. Compare especially:

Caused by: java.lang.IllegalArgumentException: Comparison method violates its general contract!
at java.util.ComparableTimSort.mergeHi (ComparableTimSort.java:870)
at java.util.ComparableTimSort.mergeAt (ComparableTimSort.java:487)
at java.util.ComparableTimSort.mergeForceCollapse (ComparableTimSort.java:426)
at java.util.ComparableTimSort.sort (ComparableTimSort.java:222)
at java.util.Arrays.sort (Arrays.java:1108)
at java.util.Arrays.sort (Arrays.java:1302)
at java.util.ArrayList.sort (ArrayList.java:1804)
at java.util.Collections.sort (Collections.java:145)
at org.apache.maven.repository.internal.DefaultVersionRangeResolver.resolveVersionRange (DefaultVersionRangeResolver.java:160)
at org.eclipse.aether.internal.impl.DefaultRepositorySystem.resolveVersionRange (DefaultRepositorySystem.java:260)
at org.codehaus.mojo.versions.api.DefaultVersionsHelper.lookupArtifactVersions (DefaultVersionsHelper.java:282)
at org.codehaus.mojo.versions.api.DefaultVersionsHelper.lookupDependencyUpdates (DefaultVersionsHelper.java:553)
at org.codehaus.mojo.versions.api.DefaultVersionsHelper.lambda$lookupDependenciesUpdates$4 (DefaultVersionsHelper.java:522)

DefaultVersionRangeResolver::resolveVersionRange:

   List<Version> versions = new ArrayList<>();
   ...
   Collections.sort( versions );   <--------

So, it looks like GenericVersion::compareTo might be the culprit here. To be checked

@andrzejj0
Copy link
Contributor

andrzejj0 commented Oct 19, 2024

https://issues.apache.org/jira/browse/MRESOLVER-314
Resolved in Resolver 1.9.5 by maven-resolver#249

@andrzejj0
Copy link
Contributor

andrzejj0 commented Oct 19, 2024

@RalfNaujokat please make sure that you're using Maven 3.9.1 or newer. Best if you could provide an (obfuscated, if necessary) output of mvn -X running the goal.

@andrzejj0 andrzejj0 removed the bug label Oct 19, 2024
@RalfNaujokat
Copy link
Author

Hi.

Sorry that i left you alone with that, i wasn't available over weekend.
I was using Maven 3.9.9 when the error occurred.

I will try to reproduce the error and send you a mvn -X output,
but to be honest, i'm not very confident that I can still manage that.

greetings
Ralf

@andrzejj0
Copy link
Contributor

andrzejj0 commented Oct 21, 2024

The issue is coming from Maven itself (we use provided Maven dependencies in plugins), so if you're in fact using 3.9.9 then it's a yet another problem with the GenericVersion::compareTo method. I would invite you to file a bug with Maven itself (project MRESOLVER in the Apache Jira).

The -X (debug) output of Maven will help verifying that. In particular, it's very important to check if there are no "unorthodox" version numbers among your dependency as that's where the comparator is having a problem with.

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

2 participants