Welcome! Please see the About page for a little more info on how this works.

+3 votes
in Tools by
closed by

Sometimes (maybe ~1% ?!) in my CI report this error for no reason.

It's a large tools-deps cli project with many local/git/maven dependencies running on CircleCI/Docker

zulu-openjdk-11
dev-utils-tools-deps 1.10.3.814

Error building classpath. 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')
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')
	at java.base/java.util.HashMap$TreeNode.moveRootToFront(HashMap.java:1882)
	at java.base/java.util.HashMap$TreeNode.putTreeVal(HashMap.java:2061)
	at java.base/java.util.HashMap.putVal(HashMap.java:633)
	at java.base/java.util.HashMap.put(HashMap.java:607)
	at java.base/java.util.HashSet.add(HashSet.java:220)
	at org.apache.maven.model.validation.DefaultModelValidator.validateId(DefaultModelValidator.java:847)
	at org.apache.maven.model.validation.DefaultModelValidator.validateEffectiveDependency(DefaultModelValidator.java:659)
	at org.apache.maven.model.validation.DefaultModelValidator.validateEffectiveDependencies(DefaultModelValidator.java:583)
	at org.apache.maven.model.validation.DefaultModelValidator.validateEffectiveModel(DefaultModelValidator.java:373)
	at org.apache.maven.model.building.DefaultModelBuilder.build(DefaultModelBuilder.java:494)
	at org.apache.maven.model.building.DefaultModelBuilder.build(DefaultModelBuilder.java:440)
	at org.apache.maven.model.building.DefaultModelBuilder.build(DefaultModelBuilder.java:430)
	at org.apache.maven.model.building.DefaultModelBuilder.importDependencyManagement(DefaultModelBuilder.java:1299)
	at org.apache.maven.model.building.DefaultModelBuilder.build(DefaultModelBuilder.java:474)
	at org.apache.maven.model.building.DefaultModelBuilder.build(DefaultModelBuilder.java:440)
	at org.apache.maven.model.building.DefaultModelBuilder.build(DefaultModelBuilder.java:430)
	at org.apache.maven.repository.internal.DefaultArtifactDescriptorReader.loadPom(DefaultArtifactDescriptorReader.java:292)
	at org.apache.maven.repository.internal.DefaultArtifactDescriptorReader.readArtifactDescriptor(DefaultArtifactDescriptorReader.java:171)
	at org.eclipse.aether.internal.impl.DefaultRepositorySystem.readArtifactDescriptor(DefaultRepositorySystem.java:255)
	at clojure.tools.deps.alpha.extensions.maven$eval1076$fn__1078.invoke(maven.clj:107)
	at clojure.lang.MultiFn.invoke(MultiFn.java:244)
	at clojure.tools.deps.alpha$expand_deps$children_task__790$fn__792$fn__793.invoke(alpha.clj:403)
	at clojure.tools.deps.alpha.util.concurrent$submit_task$task__505.invoke(concurrent.clj:34)
	at clojure.lang.AFn.call(AFn.java:18)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.lang.Thread.run(Thread.java:834)
closed with the note: Fixed in 1.11.0.1100

1 Answer

+1 vote
by

This is already logged as https://clojure.atlassian.net/browse/TDEPS-153, have some ideas on how to fix but have not had time to work on it yet.

I suspect that if you pass -Sthreads 1 that might work around it (I guess either way, would be good to know if it does).

by
Just a report that I experienced this issue on 1.10.3.967

```
openjdk version "1.8.0_302"
OpenJDK Runtime Environment (Temurin)(build 1.8.0_302-b08)
OpenJDK 64-Bit Server VM (Temurin)(build 25.302-b08, mixed mode)
```

```
Error building classpath. java.util.HashMap$Node cannot be cast to java.util.HashMap$TreeNode
java.lang.ClassCastException: java.util.HashMap$Node cannot be cast to java.util.HashMap$TreeNode
        at java.util.HashMap$TreeNode.moveRootToFront(HashMap.java:1835)
        at java.util.HashMap$TreeNode.treeify(HashMap.java:1951)
        at java.util.HashMap.treeifyBin(HashMap.java:772)
        at java.util.HashMap.putVal(HashMap.java:644)
        at java.util.HashMap.put(HashMap.java:612)
        at java.util.HashSet.add(HashSet.java:220)
        at org.apache.maven.model.validation.DefaultModelValidator.validateId(DefaultModelValidator.java:848)
        at org.apache.maven.model.validation.DefaultModelValidator.validateEffectiveDependency(DefaultModelValidator.java:660)
        at org.apache.maven.model.validation.DefaultModelValidator.validateEffectiveDependencies(DefaultModelValidator.java:584)
        at org.apache.maven.model.validation.DefaultModelValidator.validateEffectiveModel(DefaultModelValidator.java:374)
        at org.apache.maven.model.building.DefaultModelBuilder.build(DefaultModelBuilder.java:501)
        at org.apache.maven.model.building.DefaultModelBuilder.build(DefaultModelBuilder.java:437)
        at org.apache.maven.model.building.DefaultModelBuilder.importDependencyManagement(DefaultModelBuilder.java:1313)
        at org.apache.maven.model.building.DefaultModelBuilder.build(DefaultModelBuilder.java:481)
        at org.apache.maven.model.building.DefaultModelBuilder.build(DefaultModelBuilder.java:437)
        at org.apache.maven.model.building.DefaultModelBuilder.build(DefaultModelBuilder.java:252)
        at org.apache.maven.repository.internal.DefaultArtifactDescriptorReader.loadPom(DefaultArtifactDescriptorReader.java:293)
        at org.apache.maven.repository.internal.DefaultArtifactDescriptorReader.readArtifactDescriptor(DefaultArtifactDescriptorReader.java:171)
        at org.eclipse.aether.internal.impl.DefaultRepositorySystem.readArtifactDescriptor(DefaultRepositorySystem.java:257)
        at clojure.tools.deps.alpha.extensions.maven$fn__1053.invokeStatic(maven.clj:132)
        at clojure.tools.deps.alpha.extensions.maven$fn__1053.invoke(maven.clj:122)
        at clojure.lang.MultiFn.invoke(MultiFn.java:244)
        at clojure.tools.deps.alpha$expand_deps$children_task__746$fn__748$fn__749.invoke(alpha.clj:406)
        at clojure.tools.deps.alpha.util.concurrent$submit_task$task__479.invoke(concurrent.clj:34)
        at clojure.lang.AFn.call(AFn.java:18)
        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:748)
```
by
We are still seeing this error with 1.10.3.1029.
by
Should be fixed in latest 1.10.3.1058.
by
I have the same stacktrace, using the following environment:

```
$ java -version
openjdk version "11.0.10" 2021-01-19 LTS
OpenJDK Runtime Environment Corretto-11.0.10.9.1 (build 11.0.10+9-LTS)
OpenJDK 64-Bit Server VM Corretto-11.0.10.9.1 (build 11.0.10+9-LTS, mixed mode, sharing)

$ clojure --version
Clojure CLI version 1.10.3.1087
```
by
`DefaultModelValidator` appears to just not be thread-safe.

This is where the exception is thrown (maven 3.8.4):
https://github.com/apache/maven/blob/maven-3.8.4/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java#L848

validIds is a private HashSet.

This is still a HashSet in master and I don't see any issue or PR that aims to change that.

A ModelValidator instance is on a ModelBuilder instance which is on an ArtifactDescriptorReader instance, which look like it may be shared (and not constructed for each artifact request) on the DefaultRepositorySystem. Maybe. So if the systems are shared across threads, that's the culprit. Probably the ModelBuilder itself should not be shared.
by
Thanks! That’s all helpful info.
by
I've just released a Clojure CLI prerelease 1.10.3.1093 with a fix for this problem and I would appreciate any help in testing it!
by
I have bad news: I still see this with Clojure CLI version 1.11.1.1105:

```
Error building classpath. 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')
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')
    at java.base/java.util.HashMap$TreeNode.moveRootToFront(HashMap.java:1900)
    at java.base/java.util.HashMap$TreeNode.treeify(HashMap.java:2016)
    at java.base/java.util.HashMap.treeifyBin(HashMap.java:768)
    at java.base/java.util.HashMap.putVal(HashMap.java:640)
    at java.base/java.util.HashMap.put(HashMap.java:608)
    at java.base/java.util.HashSet.add(HashSet.java:220)
    at org.apache.maven.model.validation.DefaultModelValidator.validateId(DefaultModelValidator.java:848)
    at org.apache.maven.model.validation.DefaultModelValidator.validateEffectiveDependency(DefaultModelValidator.java:660)
    at org.apache.maven.model.validation.DefaultModelValidator.validateEffectiveDependencies(DefaultModelValidator.java:584)
    at org.apache.maven.model.validation.DefaultModelValidator.validateEffectiveModel(DefaultModelValidator.java:374)
    at org.apache.maven.model.building.DefaultModelBuilder.build(DefaultModelBuilder.java:501)
    at org.apache.maven.model.building.DefaultModelBuilder.build(DefaultModelBuilder.java:437)
    at org.apache.maven.model.building.DefaultModelBuilder.build(DefaultModelBuilder.java:252)
    at org.apache.maven.repository.internal.DefaultArtifactDescriptorReader.loadPom(DefaultArtifactDescriptorReader.java:297)
    at org.apache.maven.repository.internal.DefaultArtifactDescriptorReader.readArtifactDescriptor(DefaultArtifactDescriptorReader.java:175)
    at org.eclipse.aether.internal.impl.DefaultRepositorySystem.readArtifactDescriptor(DefaultRepositorySystem.java:255)
    at clojure.tools.deps.alpha.extensions.maven$read_descriptor.invokeStatic(maven.clj:115)
    at clojure.tools.deps.alpha.extensions.maven$fn__1128.invokeStatic(maven.clj:143)
    at clojure.tools.deps.alpha.extensions.maven$fn__1128.invoke(maven.clj:143)
    at clojure.lang.MultiFn.invoke(MultiFn.java:244)
    at clojure.tools.deps.alpha$expand_deps$children_task__771$fn__773$fn__774.invoke(alpha.clj:405)
    at clojure.tools.deps.alpha.util.concurrent$submit_task$task__479.invoke(concurrent.clj:35)
    at clojure.lang.AFn.call(AFn.java:18)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at java.base/java.lang.Thread.run(Thread.java:829)
```
...