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.

Race condition in JavacPlugin

See original GitHub issue

JavacPlugin.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:closed
  • Created 3 years ago
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
rsmckinneycommented, Jun 6, 2020

@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.

1reaction
rsmckinneycommented, Apr 26, 2020

Fixed in release 2020.1.7

Read more comments on GitHub >

github_iconTop 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 >

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