qaware / go-offline-maven-plugin

Maven Plugin used to download all Dependencies and Plugins required in a Maven build, so the build can be run without an internet connection afterwards.
Apache License 2.0
162 stars 15 forks source link

ConcurrentModificationException when running in parallel mode #9

Closed softwaremaverick closed 5 years ago

softwaremaverick commented 5 years ago

I didn't explicitly specify parallel mode but I believe the slave may have had it configured in the M2 settings. Passing -threads 1 resolves the following issue.

It seems there was a ConcurrentModificationException encountered when running this plugin.

The useful stacktraces are as follows:

Exception in thread "ForkJoinPool-1-worker-3" java.util.ConcurrentModificationException
    at java.util.AbstractList.hashCode(AbstractList.java:540)
    at org.eclipse.aether.internal.impl.DataPool$GraphKey.<init>(DataPool.java:383)
    at org.eclipse.aether.internal.impl.DataPool.toKey(DataPool.java:160)
    at org.eclipse.aether.internal.impl.DefaultDependencyCollector.process(DefaultDependencyCollector.java:563)
    at org.eclipse.aether.internal.impl.DefaultDependencyCollector.process(DefaultDependencyCollector.java:573)
    at org.eclipse.aether.internal.impl.DefaultDependencyCollector.collectDependencies(DefaultDependencyCollector.java:261)
    at org.eclipse.aether.internal.impl.DefaultRepositorySystem.resolveDependencies(DefaultRepositorySystem.java:342)
    at de.qaware.maven.plugin.offline.DependencyDownloader.resolveDependencies(DependencyDownloader.java:169)
    at de.qaware.maven.plugin.offline.ResolveDependenciesMojo$ResolveProjectDependenciesJob.run(ResolveDependenciesMojo.java:98)
    at java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1402)
    at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
    at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
    at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
    at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)

Exception in thread "ForkJoinPool-1-worker-1" java.util.ConcurrentModificationException
    at java.util.ArrayList$Itr.next(ArrayList.java:865)
    at java.util.AbstractList.hashCode(AbstractList.java:540)
    at org.eclipse.aether.internal.impl.DataPool$GraphKey.<init>(DataPool.java:383)
    at org.eclipse.aether.internal.impl.DataPool.toKey(DataPool.java:160)
    at org.eclipse.aether.internal.impl.DefaultDependencyCollector.process(DefaultDependencyCollector.java:563)
    at org.eclipse.aether.internal.impl.DefaultDependencyCollector.process(DefaultDependencyCollector.java:573)
    at org.eclipse.aether.internal.impl.DefaultDependencyCollector.process(DefaultDependencyCollector.java:573)
    at org.eclipse.aether.internal.impl.DefaultDependencyCollector.collectDependencies(DefaultDependencyCollector.java:261)
    at org.eclipse.aether.internal.impl.DefaultRepositorySystem.resolveDependencies(DefaultRepositorySystem.java:342)
    at de.qaware.maven.plugin.offline.DependencyDownloader.resolveDependencies(DependencyDownloader.java:169)
    at de.qaware.maven.plugin.offline.ResolveDependenciesMojo$ResolveProjectDependenciesJob.run(ResolveDependenciesMojo.java:98)
    at java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1402)
    at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
    at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
    at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
    at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)

Exception in thread "ForkJoinPool-1-worker-2" java.lang.ArrayIndexOutOfBoundsException: 1
    at java.util.ArrayList.clear(ArrayList.java:562)
    at org.apache.maven.repository.internal.DefaultModelResolver.resetRepositories(DefaultModelResolver.java:130)
    at org.apache.maven.model.building.DefaultModelBuilder.configureResolver(DefaultModelBuilder.java:596)
    at org.apache.maven.model.building.DefaultModelBuilder.build(DefaultModelBuilder.java:370)
    at org.apache.maven.repository.internal.DefaultArtifactDescriptorReader.loadPom(DefaultArtifactDescriptorReader.java:375)
    at org.apache.maven.repository.internal.DefaultArtifactDescriptorReader.readArtifactDescriptor(DefaultArtifactDescriptorReader.java:231)
    at org.eclipse.aether.internal.impl.DefaultDependencyCollector.process(DefaultDependencyCollector.java:461)
    at org.eclipse.aether.internal.impl.DefaultDependencyCollector.process(DefaultDependencyCollector.java:573)
    at org.eclipse.aether.internal.impl.DefaultDependencyCollector.process(DefaultDependencyCollector.java:573)
    at org.eclipse.aether.internal.impl.DefaultDependencyCollector.collectDependencies(DefaultDependencyCollector.java:261)
    at org.eclipse.aether.internal.impl.DefaultRepositorySystem.resolveDependencies(DefaultRepositorySystem.java:342)
    at de.qaware.maven.plugin.offline.DependencyDownloader.resolveDependencies(DependencyDownloader.java:169)
    at de.qaware.maven.plugin.offline.ResolveDependenciesMojo$ResolveProjectDependenciesJob.run(ResolveDependenciesMojo.java:98)
    at java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1402)
    at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
    at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
    at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
    at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)

Exception in thread "ForkJoinPool-1-worker-3" java.lang.NullPointerException
    at org.apache.maven.repository.internal.DefaultVersionResolver$Key.<init>(DefaultVersionResolver.java:559)
    at org.apache.maven.repository.internal.DefaultVersionResolver.resolveVersion(DefaultVersionResolver.java:183)
    at org.apache.maven.repository.internal.DefaultArtifactDescriptorReader.loadPom(DefaultArtifactDescriptorReader.java:298)
    at org.apache.maven.repository.internal.DefaultArtifactDescriptorReader.readArtifactDescriptor(DefaultArtifactDescriptorReader.java:231)
    at org.eclipse.aether.internal.impl.DefaultDependencyCollector.process(DefaultDependencyCollector.java:461)
    at org.eclipse.aether.internal.impl.DefaultDependencyCollector.collectDependencies(DefaultDependencyCollector.java:261)
    at org.eclipse.aether.internal.impl.DefaultRepositorySystem.resolveDependencies(DefaultRepositorySystem.java:342)
    at de.qaware.maven.plugin.offline.DependencyDownloader.resolveDependencies(DependencyDownloader.java:169)
    at de.qaware.maven.plugin.offline.ResolveDependenciesMojo$ResolveProjectDependenciesJob.run(ResolveDependenciesMojo.java:98)
    at java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1402)
    at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
    at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
    at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
    at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)

Exception in thread "ForkJoinPool-1-worker-2" java.util.ConcurrentModificationException
    at java.util.ArrayList$Itr.next(ArrayList.java:865)
    at java.util.AbstractList.hashCode(AbstractList.java:540)
    at org.eclipse.aether.internal.impl.DataPool$GraphKey.<init>(DataPool.java:383)
    at org.eclipse.aether.internal.impl.DataPool.toKey(DataPool.java:160)
    at org.eclipse.aether.internal.impl.DefaultDependencyCollector.process(DefaultDependencyCollector.java:563)
    at org.eclipse.aether.internal.impl.DefaultDependencyCollector.collectDependencies(DefaultDependencyCollector.java:261)
    at org.eclipse.aether.internal.impl.DefaultRepositorySystem.resolveDependencies(DefaultRepositorySystem.java:342)
    at de.qaware.maven.plugin.offline.DependencyDownloader.resolveDependencies(DependencyDownloader.java:169)
    at de.qaware.maven.plugin.offline.ResolveDependenciesMojo$ResolveProjectDependenciesJob.run(ResolveDependenciesMojo.java:98)
    at java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1402)
    at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
    at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
    at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
    at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)

Exception in thread "ForkJoinPool-1-worker-1" java.util.ConcurrentModificationException
    at java.util.ArrayList$Itr.next(ArrayList.java:865)
    at java.util.AbstractList.hashCode(AbstractList.java:540)
    at org.eclipse.aether.internal.impl.DataPool$GraphKey.<init>(DataPool.java:383)
    at org.eclipse.aether.internal.impl.DataPool.toKey(DataPool.java:160)
    at org.eclipse.aether.internal.impl.DefaultDependencyCollector.process(DefaultDependencyCollector.java:563)
    at org.eclipse.aether.internal.impl.DefaultDependencyCollector.collectDependencies(DefaultDependencyCollector.java:261)
    at org.eclipse.aether.internal.impl.DefaultRepositorySystem.resolveDependencies(DefaultRepositorySystem.java:342)
    at de.qaware.maven.plugin.offline.DependencyDownloader.resolveDependencies(DependencyDownloader.java:169)
    at de.qaware.maven.plugin.offline.ResolveDependenciesMojo$ResolveProjectDependenciesJob.run(ResolveDependenciesMojo.java:98)
    at java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1402)
    at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
    at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
    at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
    at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
Theoderich commented 5 years ago

I have just released a new version 1.2.0 of the plugin that I had in the works for a while. I completely rewrote the concurrency part of the plugin. Can you please test if the problem still persists with Version 1.2.0?

softwaremaverick commented 5 years ago

I can sometimes get successes, but sometimes I get...

[ERROR] java.util.concurrent.ExecutionException: java.lang.NullPointerException
java.lang.RuntimeException: java.util.concurrent.ExecutionException: java.lang.NullPointerException
    at org.apache.maven.lifecycle.internal.builder.multithreaded.MultiThreadedBuilder.multiThreadedProjectTaskSegmentBuild(MultiThreadedBuilder.java:173)
    at org.apache.maven.lifecycle.internal.builder.multithreaded.MultiThreadedBuilder.build(MultiThreadedBuilder.java:91)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:120)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:355)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:155)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:584)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:216)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:160)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: java.util.concurrent.ExecutionException: java.lang.NullPointerException
    at java.util.concurrent.FutureTask.report(FutureTask.java:122)
    at java.util.concurrent.FutureTask.get(FutureTask.java:192)
    at org.apache.maven.lifecycle.internal.builder.multithreaded.MultiThreadedBuilder.multiThreadedProjectTaskSegmentBuild(MultiThreadedBuilder.java:165)
    ... 15 more
Caused by: java.lang.NullPointerException
    at org.apache.maven.lifecycle.internal.builder.multithreaded.MultiThreadedBuilder$1.call(MultiThreadedBuilder.java:188)
    at org.apache.maven.lifecycle.internal.builder.multithreaded.MultiThreadedBuilder$1.call(MultiThreadedBuilder.java:184)
    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:748)

Any ideas?

softwaremaverick commented 5 years ago

https://github.com/apache/maven/commits/master/maven-core/src/main/java/org/apache/maven/lifecycle/internal/builder/multithreaded/MultiThreadedBuilder.java

I can see comments here indicating an NPE was fixed recently. I'm using Maven 3.2.5 which I cannot change.

softwaremaverick commented 5 years ago

FYI I'm currently running this plugin directly from the command line. mvn -threads 1C de.qaware.maven:go-offline-maven-plugin:1.2.0:resolve-dependencies

softwaremaverick commented 5 years ago

I have just had a successful run on Jenkins which I didn't on the earlier version and so I'm hoping that it can at least run reasonably reliably on Jenkins.

softwaremaverick commented 5 years ago

One thing to note is that the successes mentioned above on Jenkins are that I can now more reliably get successful executions of the plugin when using one thread. Previously on some branches I had failures even on single-threaded.

Did the previous version take a global thread setting? As on Jenkins previously I was passing the single thread parameter but it looked like when it failed there was a concurrent exception.

Theoderich commented 5 years ago

Version 1.1.0 had several problems that could lead to failed runs that had nothing to do with Thread settings fixed in 1.2.0. The the plugin beeing more stable on your Jenkins is a good sign that those fixes worked. Neither Version 1.1.0 nor Version 1.2.0 use the global thread setting from Maven in their internal code.

I have tried to recreate your issue and indeed when I use Maven 3.2.5 I sometimes get a NullPointerException. With Maven 3.5.4 I cannot recreate the issue.

Not sure why it happens yet, looking into it.

Theoderich commented 5 years ago

Unfortionatly, this seems to be an issue in maven core that was introduced in maven 3.1 and fixed in maven 3.5. According to the discussions in the related issue https://issues.apache.org/jira/browse/MNG-6170 this affects all aggregator plugins and there is nothing a plugin can do to solve the issue. You will have to upgrade (or downgrade) your maven.

Theoderich commented 5 years ago

Added documentation to alert users to this issue