question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ConcurrentModificationException: mutation occurred during iteration

See original GitHub issue

After 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:closed
  • Created 2 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
sashaepsteincommented, May 22, 2021

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!

0reactions
davidBcommented, May 22, 2021

Can you try with maven-scala-plugin 4.5.2 ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

java - How to avoid "ConcurrentModificationException" while ...
One alternative method is convert your List to array , iterate them and remove them directly from the ...
Read more >
java.util.ConcurrentModificationException - DigitalOcean
java.util.ConcurrentModificationException is a very common exception when working with Java collection classes. Java Collection classes are fail ...
Read more >
ConcurrentModificationException in Java - Javatpoint
This message says that the exception is thrown when the next method is called as the iterator is iterating the list and we...
Read more >
Avoiding the ConcurrentModificationException in Java
Essentially, the ConcurrentModificationException is used to fail-fast when something we are iterating on is modified. Let's prove this with ...
Read more >
How to Avoid the Concurrent Modification Exception in Java
This exception occurs when an object is attempted to be modified concurrently without permission. For example, if a Collection is modified while ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found