Bug 68721 - WebappClassLoaderBase fails with duplicate class definition
Summary: WebappClassLoaderBase fails with duplicate class definition
Status: RESOLVED FIXED
Alias: None
Product: Tomcat 10
Classification: Unclassified
Component: Catalina (show other bugs)
Version: 10.1.18
Hardware: PC Linux
: P2 normal (vote)
Target Milestone: ------
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-03-07 15:52 UTC by jonatan.schmid
Modified: 2024-03-07 18:56 UTC (History)
0 users



Attachments
reproducer web application (82.66 KB, application/zip)
2024-03-07 15:52 UTC, jonatan.schmid
Details

Note You need to log in before you can comment on or make changes to this bug.
Description jonatan.schmid 2024-03-07 15:52:17 UTC
Created attachment 39612 [details]
reproducer web application

I PROVIDED A SAMLE REPRODUCER WEB APPLICATION:

Simply unzip and run it. Additionally, I have provided more detailed descriptions and explanations in the "HELP.md" file.

**************************************************************************************
DESCRIPTION OF THE BUG:

Some implementations of ClassFileTransformer may lead to WebappClassLoaderBase performing duplicate class definitions.

If a ClassFileTransformer triggers the loading of a class that is currently in the process of being loaded by WebappClassLoaderBase, it leads to the following error:

"
java.lang.LinkageError: loader org.apache.catalina.loader.ParallelWebappClassLoader @1d562d1a attempted duplicate class definition for reproducer.webappclassloaderbug.SomeClass."


The chain of execution looks like this:

loadClass (SomeClass) ->
findClassInternal (SomeClass) ->
transform (SomeClass) ->
loadClass (SomeClass) ->
findClassInternal (SomeClass) ->
defineClass (SomeClass)

The issue arises when SomeClass is defined during the innermost (second) invocation of the findClassInternal method. Upon returning to the outermost (first) call of findClassInternal within this method, another invocation of defineClass occurs, resulting in an error. Ideally, this attempt to duplicate class definition should be avoided, as the class is already defined.

**************************************************************************************
REAL-WORLD EXAMPLE:

This error happened in a real-world application. In this case the ClassFileTransformer (or rather code excecuted inside the transformer) is the eclipse link load time weaver (org.eclipse.persistence.internal.jpa.weaving.PersistenceWeaver). The conditions for triggering this bug are intricate. If needed, I can furnish additional details about it.
Comment 1 Mark Thomas 2024-03-07 18:56:00 UTC
Thanks for the test case. It made it very easy to confirm both the bug and the fix.

This has been fixed in:
- 11.0.x for 11.0.0-M18 onwards
- 10.1.x for 10.1.20 onwards
- 9.0.x for 9.0.87 onwards
- 8.5.x for 8.5.100 onwards