ConcurrentModificationException: mutation occurred during iteration
See original GitHub issueAfter migration from Scala 2.12.7 to Scala 2.13.5, on one of my projects (the biggest) I get the following error while trying to clean compile:
Execution scala-compile-first of goal net.alchim31.maven:scala-maven-plugin:4.5.1:compile failed: mutation occurred during iteration
and exception:
java.util.ConcurrentModificationException: mutation occurred during iteration scala.collection.mutable.MutationTracker$.checkMutations(MutationTracker.scala:43) scala.collection.mutable.MutationTracker$CheckedIterator.hasNext(MutationTracker.scala:59) scala.collection.IterableOnceOps.foreach(IterableOnce.scala:563) scala.collection.IterableOnceOps.foreach$(IterableOnce.scala:561) scala.collection.AbstractIterable.foreach(Iterable.scala:919) sbt.internal.inc.ClassToAPI$.process(ClassToAPI.scala:34) sbt.internal.inc.javac.AnalyzingJavaCompiler.readAPI$1(AnalyzingJavaCompiler.scala:180) sbt.internal.inc.javac.AnalyzingJavaCompiler.$anonfun$compile$23(AnalyzingJavaCompiler.scala:205) sbt.internal.inc.classfile.JavaAnalyze$.readInheritanceDependencies$1(JavaAnalyze.scala:194) sbt.internal.inc.classfile.JavaAnalyze$.$anonfun$apply$15(JavaAnalyze.scala:211) sbt.internal.inc.classfile.JavaAnalyze$.$anonfun$apply$15$adapted(JavaAnalyze.scala:110) scala.collection.IterableOnceOps.foreach(IterableOnce.scala:563) scala.collection.IterableOnceOps.foreach$(IterableOnce.scala:561) scala.collection.AbstractIterable.foreach(Iterable.scala:919) scala.collection.IterableOps$WithFilter.foreach(Iterable.scala:889) sbt.internal.inc.classfile.JavaAnalyze$.apply(JavaAnalyze.scala:110) sbt.internal.inc.javac.AnalyzingJavaCompiler.$anonfun$compile$21(AnalyzingJavaCompiler.scala:205) sbt.internal.inc.javac.AnalyzingJavaCompiler.$anonfun$compile$21$adapted(AnalyzingJavaCompiler.scala:199) scala.collection.IterableOnceOps.foreach(IterableOnce.scala:563) scala.collection.IterableOnceOps.foreach$(IterableOnce.scala:561) scala.collection.AbstractIterable.foreach(Iterable.scala:919) scala.collection.IterableOps$WithFilter.foreach(Iterable.scala:889) sbt.internal.inc.javac.AnalyzingJavaCompiler.$anonfun$compile$19(AnalyzingJavaCompiler.scala:199) scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.scala:18) sbt.internal.inc.javac.AnalyzingJavaCompiler.timed(AnalyzingJavaCompiler.scala:251) sbt.internal.inc.javac.AnalyzingJavaCompiler.compile(AnalyzingJavaCompiler.scala:199) sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compileJava$1(MixedAnalyzingCompiler.scala:98) scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.scala:18) sbt.internal.inc.MixedAnalyzingCompiler.timed(MixedAnalyzingCompiler.scala:241) sbt.internal.inc.MixedAnalyzingCompiler.compileJava(MixedAnalyzingCompiler.scala:61) sbt.internal.inc.MixedAnalyzingCompiler.compileJava0$1(MixedAnalyzingCompiler.scala:191) sbt.internal.inc.MixedAnalyzingCompiler.compile(MixedAnalyzingCompiler.scala:204) sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1(IncrementalCompilerImpl.scala:528) sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1$adapted(IncrementalCompilerImpl.scala:528) sbt.internal.inc.Incremental$.$anonfun$apply$5(Incremental.scala:174) sbt.internal.inc.Incremental$.$anonfun$apply$5$adapted(Incremental.scala:172) sbt.internal.inc.Incremental$$anon$2.run(Incremental.scala:457) sbt.internal.inc.IncrementalCommon$CycleState.next(IncrementalCommon.scala:116) sbt.internal.inc.IncrementalCommon$$anon$1.next(IncrementalCommon.scala:56) sbt.internal.inc.IncrementalCommon$$anon$1.next(IncrementalCommon.scala:52) sbt.internal.inc.IncrementalCommon.cycle(IncrementalCommon.scala:261) sbt.internal.inc.Incremental$.$anonfun$incrementalCompile$8(Incremental.scala:412) sbt.internal.inc.Incremental$.withClassfileManager(Incremental.scala:499) sbt.internal.inc.Incremental$.incrementalCompile(Incremental.scala:399) sbt.internal.inc.Incremental$.apply(Incremental.scala:166) sbt.internal.inc.IncrementalCompilerImpl.compileInternal(IncrementalCompilerImpl.scala:528) sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileIncrementally$1(IncrementalCompilerImpl.scala:482) sbt.internal.inc.IncrementalCompilerImpl.handleCompilationError(IncrementalCompilerImpl.scala:332) sbt.internal.inc.IncrementalCompilerImpl.compileIncrementally(IncrementalCompilerImpl.scala:420) sbt.internal.inc.IncrementalCompilerImpl.compile(IncrementalCompilerImpl.scala:137) sbt_inc.SbtIncrementalCompiler.compile(SbtIncrementalCompiler.java:179) scala_maven.ScalaCompilerSupport.incrementalCompile(ScalaCompilerSupport.java:356) scala_maven.ScalaCompilerSupport.compile(ScalaCompilerSupport.java:113) scala_maven.ScalaCompilerSupport.doExecute(ScalaCompilerSupport.java:88) scala_maven.ScalaMojoSupport.execute(ScalaMojoSupport.java:308) org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:137) org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:210) org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:156) org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:148) org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117) org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81) org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:56) org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128) org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:305) org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:192) org.apache.maven.DefaultMaven.execute(DefaultMaven.java:105) org.apache.maven.cli.MavenCli.execute(MavenCli.java:956) org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288) org.apache.maven.cli.MavenCli.main(MavenCli.java:192) java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) java.base/java.lang.reflect.Method.invoke(Method.java:566) org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289) org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229) org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415) org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
I tried different JDK (11, 12, 16) but the problem persisted. Interestingly, this problem is seen only on the clean state, if I repeat mvn compile
after the above error, it works fine.
Another point is that the same project is built perfectly fine using SBT.
Here is the excerpt from pom.xml with plugin config:
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>4.5.1</version>
<executions>
<execution>
<id>scala-compile-first</id>
<phase>process-resources</phase>
<goals>
<goal>add-source</goal>
<goal>compile</goal>
</goals>
</execution>
</executions>
<configuration>
<scalaVersion>${scala.version}</scalaVersion> <!-- Scala version is detected from dependency to scala-library -->
<recompileMode>incremental</recompileMode>
<args>
<arg>-unchecked</arg>
<arg>-deprecation</arg>
<arg>-feature</arg>
</args>
<javacArgs>
<javacArg>-Xlint:unchecked</javacArg>
<javacArg>-Xlint:deprecation</javacArg>
</javacArgs>
</configuration>
</plugin>
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (2 by maintainers)
Top GitHub Comments
yes, you’ve made it! My project has 3 modules, and using JDK 16 and the previous versions of the plugin none of those modules got compiled without the mutation exception. Once I upgraded the plugin to 4.5.2 everything started to compile. Thank you, David, a ton and have a great weekend!
Can you try with maven-scala-plugin 4.5.2 ?