Race condition in JavacPlugin
See original GitHub issueJavacPlugin.loadJavacParserClass()
checks if the classloader contains ManJavacParser
, and if not, adds it.
When building with SBT, this method is invoked multiple times, sometimes concurrently, which can result in an “attempted duplicate class definition” error:
java.lang.LinkageError: loader 'app' (instance of jdk.internal.loader.ClassLoaders$AppClassLoader) attempted duplicate class definition for com.sun.tools.javac.parser.ManJavacParser.
at java.base/java.lang.ClassLoader.defineClass1(Native Method)
...
It looks like loadJavacParserClass()
should be acquiring a lock first. Adding a synchronized(classLoader) {...}
around the body of this method appears to prevent the error.
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (6 by maintainers)
Top Results From Across the Web
Race Condition in Java - Javatpoint
A condition in which the critical section (a part of the program where shared memory is accessed) is concurrently executed by two or...
Read more >Race condition in multithreading and it's solution in java
So we can solve race condition by using either synchronized block or synchronized method. When no two threads can access same resource at...
Read more >Race Conditions | Eclipse Plugins, Bundles and Products
vmlens, testing multi-threaded applications on the JVM made easy. Simply running your tests with multiple threads does not work. Bugs depend on ...
Read more >multithreading - What is a race condition? - Stack Overflow
A race condition occurs when two or more threads can access shared data and they try to change it at the same time....
Read more >What is Race Condition in Java Multithreading? Examples
Race condition in Java is a type of concurrency bug or issue that is introduced in your program because of parallel execution of...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@iadcode I don’t have any experience with SBT, however using the class lock is probably okay for this use-case. FWIW, SBT is the first reported case of this kind for Manifold. It could be that this issue exists in Maven and/or Gradle too, but that no one uses Manifold in parallel builds. I’ll experiment.
Btw, assuming your project uses Scala, the next Manifold release will support Scala and Kotlin as well as Android. It’s almost there.
Fixed in release 2020.1.7