How do I solve this LinkageError duplicate class definition?

373 Views Asked by At

I'm using IcedTea-Web to run a java application with jnlp/javaws. The application used to work fine running with Java 8 and java web start. I'm trying to move to Java 17 and IcedTea-Web.

The error I have is :

java.lang.LinkageError: loader net.sourceforge.jnlp.runtime.JNLPClassLoader @55e1be49 attempted duplicate class definition for com.mypackage.MyClass. (com.mypackage.MyClass is in unnamed module of loader net.sourceforge.jnlp.runtime.JNLPClassLoader @55e1be49, parent loader 'bootstrap')

Issue happens when application tries to load classes from their names using ClassLoader net.sourceforge.jnlp.runtime.JNLPClassLoader.

Is there a known bug of race condition causing LinkageError "duplicate class definition" in IcedTea-Web's JNLPClassLoader ?

1

There are 1 best solutions below

0
On

Yes, there is a known issue with the IcedTea-Web's JNLPClassLoader that can lead to a race condition, causing a LinkageError with the message "attempted duplicate class definition". The error was reported to occur when starting IcedTea-Web with certain project applications, such as the Volvo RTDMS project. The likely cause was identified as a lack of proper synchronization in net.sourceforge.jnlp.runtime.classloader.JNLPClassLoader.loadClass(final String name)​

A fix for this issue was provided in a GitHub pull request. The fix involves adding thread synchronization on the class loader to prevent the duplicate class loading issue. Apparently, this fix was tested extensively in the Volvo project and was found to work fine without affecting performance. The pull request with the fix was subsequently merged into the AdoptOpenJDK:master on March 18, 2021​​.

Moreover, it seems the fix is yet to be included in an upcoming release.