Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Equinox » Calls to ClassLoader.getSystemClassLoader that are beyond my control
Calls to ClassLoader.getSystemClassLoader that are beyond my control [message #84751] Thu, 22 March 2007 12:55 Go to next message
Eclipse UserFriend
Originally posted by: william.weatherill.lhasalimited.org

Hi,



I'm fairly new to Equinox and OSGi in general. My question is regarding
classloading and is best explained with an example:



Suppose I write a bundle (called MyBundle) that relies on some 3rd party
code. I decide to wrap this 3rd party code in its own bundle (called
ExternalBundleA). This 3rd party code also relies on some other 3rd party
code which I also choose to bundle up (called ExternalBundleB).



What happens if some code in ExternalBundleA makes a call to
ClassLoader.getSystemClassLoader() and uses the resulting ClassLoader to
load a class that is from it's external dependency (which I put into
ExternalBundleB). Will I get a ClassNotFoundException?



I guess in a simple non-OSGi application all classes would be on the system
classpath and so the developers of the code that I've put into
ExternalBundleA were quite legitimate in their class loading strategy.
However by bundling up their code I am using it in a way that they never
intended.



Is this scenario possible? If so then does it suggest that it might not
always be possible to successfully bundle some 3rd party code?



Thank you in advance



Will
Re: Calls to ClassLoader.getSystemClassLoader that are beyond my control [message #87353 is a reply to message #84751] Wed, 02 May 2007 18:59 Go to previous messageGo to next message
Thomas Watson is currently offline Thomas WatsonFriend
Messages: 503
Registered: July 2009
Senior Member
Will Weatherill wrote:
>
> What happens if some code in ExternalBundleA makes a call to
> ClassLoader.getSystemClassLoader() and uses the resulting ClassLoader to
> load a class that is from it's external dependency (which I put into
> ExternalBundleB). Will I get a ClassNotFoundException?
>

Yes you should get a ClassNotFoundException. This is because the app
classloader returned by ClassLoader.getSystemClassLoader() does not have
any bundle content on its classpath. In Eclipse the app classloader
only has the launcher boot strap code on its classpath.

>
>
> I guess in a simple non-OSGi application all classes would be on the system
> classpath and so the developers of the code that I've put into
> ExternalBundleA were quite legitimate in their class loading strategy.

I'm not sure about that. Why are they not just using their own
classloader? Why do they need to get the app classloader if they
already assume they are loaded by the app classloader? I realize that
is not very useful since you probably have no control over what this 3rd
party code is doing ;-)

> However by bundling up their code I am using it in a way that they never
> intended.

True, bundling up 3rd party code is not always straight forward in OSGi,
particularly when a context classloader is used. From what you describe
it does not sound like your 3rd party code is using the context
classloader but the problem is similar.

>
>
>
> Is this scenario possible? If so then does it suggest that it might not
> always be possible to successfully bundle some 3rd party code?

True, it is not always possible to successfully bundle all 3rd party code.

Tom.
Re: Calls to ClassLoader.getSystemClassLoader that are beyond my control [message #88092 is a reply to message #87353] Sun, 13 May 2007 11:36 Go to previous message
Martin Lippert is currently offline Martin LippertFriend
Messages: 124
Registered: July 2009
Senior Member
Hi,

>> What happens if some code in ExternalBundleA makes a call to
>> ClassLoader.getSystemClassLoader() and uses the resulting ClassLoader
>> to load a class that is from it's external dependency (which I put
>> into ExternalBundleB). Will I get a ClassNotFoundException?
>
> Yes you should get a ClassNotFoundException. This is because the app
> classloader returned by ClassLoader.getSystemClassLoader() does not have
> any bundle content on its classpath. In Eclipse the app classloader
> only has the launcher boot strap code on its classpath.

Another way around this problem could be to use the Equinox Aspects
incubator code that would allow you to weave an around advice into that
library bundle to replace calls to ClassLoader.getSystemClassLoader()
with calls to get the bundle classloader. Just an idea if nothing else
helps...

Best regards,
-Martin
Previous Topic:RPC via Web services to an RCP application
Next Topic:Service Factory...
Goto Forum:
  


Current Time: Mon Jul 08 11:24:47 GMT 2024

Powered by FUDForum. Page generated in 0.03976 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top