Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 345500 - LinkageError caused by duplicate loadclass calls for the same class on the same ClassLoader
Summary: LinkageError caused by duplicate loadclass calls for the same class on the sa...
Status: RESOLVED FIXED
Alias: None
Product: Equinox
Classification: Eclipse Project
Component: Framework (show other bugs)
Version: 3.6   Edit
Hardware: Macintosh Mac OS X - Carbon (unsup.)
: P3 normal (vote)
Target Milestone: 3.7 RC1   Edit
Assignee: Thomas Watson CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-05-11 16:52 EDT by Kevan Miller CLA
Modified: 2011-05-11 19:08 EDT (History)
1 user (show)

See Also:
dj.houghton: review+


Attachments
patch (1.80 KB, patch)
2011-05-11 17:18 EDT, Thomas Watson CLA
no flags Details | Diff
new patch (1.76 KB, patch)
2011-05-11 17:40 EDT, DJ Houghton CLA
no flags Details | Diff
stacktrace of the problem (7.70 KB, text/plain)
2011-05-11 19:08 EDT, Kevan Miller CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Kevan Miller CLA 2011-05-11 16:52:19 EDT
Build Identifier: 3.6.x and 3.7

In the Apache Geronimo project, we've encountered some classloading issues which have resulted in LinkageError's being thrown by the ClassLoader. Basic problem is that in some instances, defineClass will be called twice for the same Class on the same Thread. When this occurs, the initial defineClass will throw a LinkageError. Felix has code which will detect a cyclical load. So, this problem doesn't exist on Felix. There may be some debate on whether or not this is an Equinox problem. But would be great if Equinox could detect this situation, also...

Geronimo Jira is here -- https://issues.apache.org/jira/browse/GERONIMO-5751 

Reproducible: Always
Comment 1 Thomas Watson CLA 2011-05-11 17:18:25 EDT
Created attachment 195437 [details]
patch

This patch will detect recursive calls to defineClass for the same class name and will instead cause a ClassNotFoundException to be thrown.  This will avoid the LinkageError.  This helps in the Geronimo case because the scenario involves a class transformation during defineClass which then causes another class loader to be used to try and load the same class and that eventually delegates to the same class loader which is trying to define the class.


Apparently the inner defineClass succeeds!  But then the outer one which initiated the whole thing failes with a LinkageError.  This transformation code can handle the CNFE, but there is nothing it can do about a LinkageError being thrown from the initiating defineClass.

Purely from the frameworks perspective, I am not sure if a CNFE exception is better than a LinkageError.  But I think it would be good to get consistent behavior between Felix and Equinox on this.
Comment 2 DJ Houghton CLA 2011-05-11 17:40:20 EDT
Created attachment 195440 [details]
new patch

Tom and I talked this over and here is a slightly modified patch.
Comment 3 DJ Houghton CLA 2011-05-11 17:57:03 EDT
Patch released.
Comment 4 Kevan Miller CLA 2011-05-11 19:08:14 EDT
Created attachment 195448 [details]
stacktrace of the problem

Thanks! That looks like the patch should do the trick. 

For historical documentation I've attached the stacktrace of the problem.

The ClassLoader.defineClass() call on line 4 of the file (your "inner" call) will succeed. 

However, when the call stack unwinds to the ClassLoader.defineClass1(Native Method), on line 38 of the file (your "outer" call, that defineClass1() invocation will throw a LinkageError.

ClassLoader instances are the same on line 4 and 38. And both are defining the same class.  

Throwing CNFE or LinkageError from the "inner" call will work -- we have code for either case.  Consistency sounds good to me.

Many thanks for the quick solution.