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

switch form v1.1.5 to v1.1.6 on java-9 produces java.util.ConcurrentModificationException #538

Closed
Andrei-Pozolotin opened this issue May 6, 2018 · 6 comments

Comments

@Andrei-Pozolotin
Copy link
Contributor

project:
https://github.com/random-maven/scalor-maven-plugin

after switch switch form zinc v1.1.5 to zinc v1.1.6:

builds fine on java-8:
https://travis-ci.org/random-maven/scalor-maven-plugin/builds/375394197

build fails on java-9, trace:
https://travis-ci.org/random-maven/scalor-maven-plugin/jobs/375394199#L2269

[INFO] java.util.ConcurrentModificationException
[INFO]     at java.util.HashMap.computeIfAbsent (HashMap.java:1139)
[INFO]     at xsbt.ExtractAPI.processType (ExtractAPI.scala:504)
[INFO]     at xsbt.ExtractAPI.$anonfun$types$1 (ExtractAPI.scala:185)
[INFO]     at scala.collection.TraversableLike.$anonfun$map$1 (TraversableLike.scala:234)
[INFO]     at scala.collection.IndexedSeqOptimized.foreach (IndexedSeqOptimized.scala:32)
[INFO]     at scala.collection.IndexedSeqOptimized.foreach$ (IndexedSeqOptimized.scala:29)
[INFO]     at scala.collection.mutable.ArrayOps$ofRef.foreach (ArrayOps.scala:191)
[INFO]     at scala.collection.TraversableLike.map (TraversableLike.scala:234)
[INFO]     at scala.collection.TraversableLike.map$ (TraversableLike.scala:227)
[INFO]     at scala.collection.mutable.ArrayOps$ofRef.map (ArrayOps.scala:191)
[INFO]     at xsbt.ExtractAPI.types (ExtractAPI.scala:185)
@eed3si9n
Copy link
Member

eed3si9n commented May 6, 2018

Thanks for the report @Andrei-Pozolotin!

I suspect the direct cause might be 52959c9 but I am not sure if it somehow introduced a concurrency issue, just happened to uncover an existing one.
Ping @retronym.

@eed3si9n
Copy link
Member

eed3si9n commented May 6, 2018

processType looks like this:

  private def processType(in: Symbol, t: Type): xsbti.api.Type = {
    typeCache.computeIfAbsent((in, t),
                              new java.util.function.Function[(Symbol, Type), xsbti.api.Type] {
                                def apply(key: (Symbol, Type)) = makeType(in, t)
                              })
  }

It checks if (in, t) pair is in typeCache, and calls makeType(in, t), and modifies typeCache.
Inside of def makeType(...) there are multiple calls to processType(...). Is that enough to cause ConcurrentModificationException single-threadedly?

@eed3si9n
Copy link
Member

eed3si9n commented May 6, 2018

Thankfully the unit test is able to reproduce java.util.ConcurrentModificationException running on OracleJDK 10.

steps

  1. jenv shell 10

  2. Comment out inlining flags in build.sbt:

    scalaBinaryVersion.value match {
      case "2.12" => old // ++ List("-opt-inline-from:<sources>", "-opt:l:inline", "-Yopt-inline-heuristics:at-inline-annotated")
  1. From sbt:
sbt:zinc Root> compilerBridgeTest/testOnly xsbt.ExtractAPISpecification

problems

[info] ExtractAPISpecification:
[info] ExtractAPI
[info] - should give stable names to members of existential types in method signatures *** FAILED ***
[info]   java.util.ConcurrentModificationException:
[info]   at java.base/java.util.HashMap.computeIfAbsent(HashMap.java:1139)
[info]   at xsbt.ExtractAPI.processType(ExtractAPI.scala:504)
[info]   at xsbt.ExtractAPI.typeParameter(ExtractAPI.scala:609)
[info]   at xsbt.ExtractAPI.$anonfun$typeParameters$1(ExtractAPI.scala:596)
[info]   at scala.collection.immutable.List.map(List.scala:283)
[info]   at xsbt.ExtractAPI.typeParameters(ExtractAPI.scala:596)
[info]   at xsbt.ExtractAPI.typeParameters(ExtractAPI.scala:594)
[info]   at xsbt.ExtractAPI.xsbt$ExtractAPI$$mkClassLike(ExtractAPI.scala:680)
[info]   at xsbt.ExtractAPI$$anon$5.apply(ExtractAPI.scala:661)
[info]   at xsbt.ExtractAPI$$anon$5.apply(ExtractAPI.scala:660)
[info]   ...

eed3si9n added a commit to eed3si9n/zinc that referenced this issue May 6, 2018
This reverts commit 52959c9.
Fixes sbt#538

The use of `java.util.HashMap` causes `java.util.ConcurrentModificationException` on JDK 9 and JDK 10. This is likely because `processType` recursively end up calling `processType` while modifying `typeCache`.
This was referenced May 6, 2018
@eed3si9n
Copy link
Member

eed3si9n commented May 7, 2018

Fixed in #539

@eed3si9n eed3si9n closed this as completed May 7, 2018
@Andrei-Pozolotin
Copy link
Contributor Author

1.1.7 works, thank you

@eed3si9n
Copy link
Member

eed3si9n commented May 8, 2018

@Andrei-Pozolotin Awesome. Thanks for the confirmation.

eed3si9n added a commit to eed3si9n/scala that referenced this issue May 14, 2019
This reverts commit 52959c9e40be56d17fdf92c8d3c2662911d3e4bd.
Fixes sbt/zinc#538

The use of `java.util.HashMap` causes `java.util.ConcurrentModificationException` on JDK 9 and JDK 10. This is likely because `processType` recursively end up calling `processType` while modifying `typeCache`.
lrytz pushed a commit to lrytz/scala that referenced this issue Nov 5, 2019
This reverts commit 52959c9e40be56d17fdf92c8d3c2662911d3e4bd.
Fixes sbt/zinc#538

The use of `java.util.HashMap` causes `java.util.ConcurrentModificationException` on JDK 9 and JDK 10. This is likely because `processType` recursively end up calling `processType` while modifying `typeCache`.

Rewritten from sbt/zinc@7a1995d
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