mojohaus/versions

Regression in 2.16.1: class java.util.HashMap$Node cannot be cast to class java.util.HashMap$TreeNode

Closed this issue · 7 comments

Hi,

i found a regression from 2.16.0 to 2.16.1.

While running display-dependency-updates, i get
Unable to acquire metadata for dependencies java.util.stream.ReferencePipeline$2@35ee466f:
java.lang.ClassCastException: class java.util.HashMap$Node cannot be cast to class java.util.HashMap$TreeNode (java.util.HashMap$Node and java.util.HashMap$TreeNode are in module java.base of loader 'bootstrap')

The last visible action was:
Downloading from ***/io/prometheus/simpleclient/maven-metadata.xml

greetings
Ralf

Can you provide a simple project which can reproduce it?

Actually, i can't reproduce it myself, right now it is working.
Could be some cached broken files?
Vers. 2.16.0 did not had the problem, but 2.16.1 crashed.

Sorry for that, maybe we can close this issue,
and if i notice this again, i will keep you informed.

ok, if you can reproduce please reopen.

Hi,
I too have the same exception with one of my jenkins job, while generating a mvn site with version reports.
I struggle to replicate this problem on my box and the jenkins env is a bit complex (docker cloud..) to replicate
I managed to get the following trace by activating the error reporting in maven (mvn --errors...) :

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-site-plugin:4.0.0-M9:site (default-site) on project xxxxxxxx: Error generating versions-maven-plugin:2.16.1:dependency-updates-report report: org.codehaus.mojo.versions.api.VersionRetrievalException: Unable to acquire metadata for dependencies java.util.stream.ReferencePipeline$2@405e3e35: java.lang.ClassCastException: java.util.HashMap$Node cannot be cast to java.util.HashMap$TreeNode -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-site-plugin:4.0.0-M9:site (default-site) on project xxxxxxxx: Error generating versions-maven-plugin:2.16.1:dependency-updates-report report
    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:266)
    at java.util.concurrent.Executors$RunnableAdapter.call (Executors.java:511)
    at java.util.concurrent.FutureTask.run (FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:624)
    at java.lang.Thread.run (Thread.java:750)
Caused by: org.apache.maven.plugin.MojoExecutionException: Error generating versions-maven-plugin:2.16.1:dependency-updates-report report
    at org.apache.maven.plugins.site.render.SiteMojo.execute (SiteMojo.java:122)
    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:266)
    at java.util.concurrent.Executors$RunnableAdapter.call (Executors.java:511)
    at java.util.concurrent.FutureTask.run (FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:624)
    at java.lang.Thread.run (Thread.java:750)
Caused by: org.apache.maven.doxia.siterenderer.RendererException: Error generating versions-maven-plugin:2.16.1:dependency-updates-report report
    at org.apache.maven.plugins.site.render.ReportDocumentRenderer.renderDocument (ReportDocumentRenderer.java:209)
    at org.apache.maven.doxia.siterenderer.DefaultSiteRenderer.render (DefaultSiteRenderer.java:298)
    at org.apache.maven.plugins.site.render.SiteMojo.renderNonDoxiaDocuments (SiteMojo.java:280)
    at org.apache.maven.plugins.site.render.SiteMojo.renderLocale (SiteMojo.java:162)
    at org.apache.maven.plugins.site.render.SiteMojo.execute (SiteMojo.java:115)
    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:266)
    at java.util.concurrent.Executors$RunnableAdapter.call (Executors.java:511)
    at java.util.concurrent.FutureTask.run (FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:624)
    at java.lang.Thread.run (Thread.java:750)
Caused by: java.lang.RuntimeException: org.codehaus.mojo.versions.api.VersionRetrievalException: Unable to acquire metadata for dependencies java.util.stream.ReferencePipeline$2@405e3e35: java.lang.ClassCastException: java.util.HashMap$Node cannot be cast to java.util.HashMap$TreeNode
    at org.codehaus.mojo.versions.AbstractDependencyUpdatesReportMojo.doGenerateReport (AbstractDependencyUpdatesReportMojo.java:183)
    at org.codehaus.mojo.versions.AbstractVersionsReport.executeReport (AbstractVersionsReport.java:209)
    at org.apache.maven.reporting.AbstractMavenReport.generate (AbstractMavenReport.java:289)
    at org.apache.maven.plugins.site.render.ReportDocumentRenderer.renderDocument (ReportDocumentRenderer.java:198)
    at org.apache.maven.doxia.siterenderer.DefaultSiteRenderer.render (DefaultSiteRenderer.java:298)
    at org.apache.maven.plugins.site.render.SiteMojo.renderNonDoxiaDocuments (SiteMojo.java:280)
    at org.apache.maven.plugins.site.render.SiteMojo.renderLocale (SiteMojo.java:162)
    at org.apache.maven.plugins.site.render.SiteMojo.execute (SiteMojo.java:115)
    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:266)
    at java.util.concurrent.Executors$RunnableAdapter.call (Executors.java:511)
    at java.util.concurrent.FutureTask.run (FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:624)
    at java.lang.Thread.run (Thread.java:750)
Caused by: org.codehaus.mojo.versions.api.VersionRetrievalException: Unable to acquire metadata for dependencies java.util.stream.ReferencePipeline$2@405e3e35: java.lang.ClassCastException: java.util.HashMap$Node cannot be cast to java.util.HashMap$TreeNode
    at org.codehaus.mojo.versions.api.DefaultVersionsHelper.lookupDependenciesUpdates (DefaultVersionsHelper.java:544)
    at org.codehaus.mojo.versions.api.DefaultVersionsHelper.lookupDependenciesUpdates (DefaultVersionsHelper.java:554)
    at org.codehaus.mojo.versions.AbstractDependencyUpdatesReportMojo.doGenerateReport (AbstractDependencyUpdatesReportMojo.java:154)
    at org.codehaus.mojo.versions.AbstractVersionsReport.executeReport (AbstractVersionsReport.java:209)
    at org.apache.maven.reporting.AbstractMavenReport.generate (AbstractMavenReport.java:289)
    at org.apache.maven.plugins.site.render.ReportDocumentRenderer.renderDocument (ReportDocumentRenderer.java:198)
    at org.apache.maven.doxia.siterenderer.DefaultSiteRenderer.render (DefaultSiteRenderer.java:298)
    at org.apache.maven.plugins.site.render.SiteMojo.renderNonDoxiaDocuments (SiteMojo.java:280)
    at org.apache.maven.plugins.site.render.SiteMojo.renderLocale (SiteMojo.java:162)
    at org.apache.maven.plugins.site.render.SiteMojo.execute (SiteMojo.java:115)
    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:266)
    at java.util.concurrent.Executors$RunnableAdapter.call (Executors.java:511)
    at java.util.concurrent.FutureTask.run (FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:624)
    at java.lang.Thread.run (Thread.java:750)
Caused by: java.util.concurrent.ExecutionException: java.lang.ClassCastException: java.util.HashMap$Node cannot be cast to java.util.HashMap$TreeNode
    at java.util.concurrent.FutureTask.report (FutureTask.java:122)
    at java.util.concurrent.FutureTask.get (FutureTask.java:192)
    at org.codehaus.mojo.versions.api.DefaultVersionsHelper.lookupDependenciesUpdates (DefaultVersionsHelper.java:537)
    at org.codehaus.mojo.versions.api.DefaultVersionsHelper.lookupDependenciesUpdates (DefaultVersionsHelper.java:554)
    at org.codehaus.mojo.versions.AbstractDependencyUpdatesReportMojo.doGenerateReport (AbstractDependencyUpdatesReportMojo.java:154)
    at org.codehaus.mojo.versions.AbstractVersionsReport.executeReport (AbstractVersionsReport.java:209)
    at org.apache.maven.reporting.AbstractMavenReport.generate (AbstractMavenReport.java:289)
    at org.apache.maven.plugins.site.render.ReportDocumentRenderer.renderDocument (ReportDocumentRenderer.java:198)
    at org.apache.maven.doxia.siterenderer.DefaultSiteRenderer.render (DefaultSiteRenderer.java:298)
    at org.apache.maven.plugins.site.render.SiteMojo.renderNonDoxiaDocuments (SiteMojo.java:280)
    at org.apache.maven.plugins.site.render.SiteMojo.renderLocale (SiteMojo.java:162)
    at org.apache.maven.plugins.site.render.SiteMojo.execute (SiteMojo.java:115)
    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:266)
    at java.util.concurrent.Executors$RunnableAdapter.call (Executors.java:511)
    at java.util.concurrent.FutureTask.run (FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:624)
    at java.lang.Thread.run (Thread.java:750)
Caused by: java.lang.ClassCastException: java.util.HashMap$Node cannot be cast to java.util.HashMap$TreeNode
    at java.util.HashMap$TreeNode.moveRootToFront (HashMap.java:1859)
    at java.util.HashMap$TreeNode.treeify (HashMap.java:1975)
    at java.util.HashMap.treeifyBin (HashMap.java:773)
    at java.util.HashMap.putVal (HashMap.java:645)
    at java.util.HashMap.put (HashMap.java:613)
    at org.codehaus.mojo.versions.api.DefaultVersionsHelper.getBestFitRule (DefaultVersionsHelper.java:457)
    at org.codehaus.mojo.versions.api.DefaultVersionsHelper.getIgnoredVersions (DefaultVersionsHelper.java:355)
    at org.codehaus.mojo.versions.api.DefaultVersionsHelper.lookupArtifactVersions (DefaultVersionsHelper.java:259)
    at org.codehaus.mojo.versions.api.DefaultVersionsHelper.lookupDependencyUpdates (DefaultVersionsHelper.java:564)
    at org.codehaus.mojo.versions.api.DefaultVersionsHelper.lambda$lookupDependenciesUpdates$4 (DefaultVersionsHelper.java:533)
    at java.util.concurrent.FutureTask.run (FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:624)
    at java.lang.Thread.run (Thread.java:750)

My env was

$ mvn --version
Apache Maven 3.9.8 (36645f6c9b5079805ea5009217e36f2cffd34256)
Maven home: /home/xxxxxxx/.sdkman/candidates/maven/current
Java version: 1.8.0_402, vendor: Temurin, runtime: /home/xxxxxx/.sdkman/candidates/java/8.0.402-tem/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "6.5.0-44-generic", arch: "amd64", family: "unix"

and the command line was

mvn site -T2C  --errors

ie. a multi thread run. The site mojo is marked thread safe.
and the dependency-updates-report mojo also.
Note: on my jenkins instance, I do not run in parallel mode. I was lucky to reproduce I think.

The stack trace lead me to this question https://stackoverflow.com/questions/29967401/strange-hashmap-exception-hashmapnode-cannot-be-cast-to-hashmaptreenode

One of the last comment makes me wonder if the problem (and fix ie. ConcurrentHashMap) is the the unsafe map used by DefaultVersionsHelper.getBestFitRule ?

    private final Map<String, Rule> artifactBestFitRule = new HashMap<>();

see
https://github.com/mojohaus/versions/blob/2.16.1/versions-common/src/main/java/org/codehaus/mojo/versions/api/DefaultVersionsHelper.java#L457
and
https://github.com/mojohaus/versions/blob/2.16.1/versions-common/src/main/java/org/codehaus/mojo/versions/api/DefaultVersionsHelper.java#L150

Thx

there are other new hashMap in the code. Need to check each one if it is used in multithread env or not..

Hi, slawekjaranowski I wonder I you have see my comments above ?. Do I need to open another issue? thx