Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Class loading in SWT Event Thread
Class loading in SWT Event Thread [message #1124378] Thu, 03 October 2013 09:24 Go to next message
Jan Krakora is currently offline Jan Krakora
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
I'm little confused about class loading in the Eclipse runtime.

I have my own plugin that uses this code:
Display.getDefault().asyncExec(new Runnable() {
    public void run() {
        MyClass class = new MyClass();
        ....
    }
)};

Since the code in run() is executed on the SWT Event thread, I would like to know what class loader will be used for loading the MyClass.class.
Re: Class loading in SWT Event Thread [message #1125078 is a reply to message #1124378] Fri, 04 October 2013 02:11 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 25910
Registered: July 2009
Senior Member
Jan,

Set a breakpoint in the debugger an you can see what class loader is
used. In general with OSGi, that's quite a complex question. You
should expect that the class loader of the bundle in which you've
defined the class containing the code you show below to be used. So
that bundle better define MyClass, have a dependency on a bundle that
defines MyClass and exports it, or you might need to deal with things
like buddy class loading (but that doesn't apply for your specific
hard-coded class name below.

Why are you even asking it? You're having some specific problem and you
think the answer to this question will help solve that problem?

On 03/10/2013 3:24 PM, Jan Krakora wrote:
> I'm little confused about class loading in the Eclipse runtime.
> I have my own plugin that uses this code:
>
> Display.getDefault().asyncExec(new Runnable() {
> public void run() {
> MyClass class = new MyClass();
> ....
> }
> )};
>
> Since the code in run() is executed on the SWT Event thread, I would
> like to know what class loader will be used for loading the
> MyClass.class.
Re: Class loading in SWT Event Thread [message #1125152 is a reply to message #1125078] Fri, 04 October 2013 03:55 Go to previous messageGo to next message
Jan Krakora is currently offline Jan Krakora
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
Well, my problem is in using lambdaj on the SWT Event thread.

Let's say I have:

  • plugin A containing MyClass
  • plugin B containing ByClassB that define the code below
  • com.google.lambdaj plugin
  • plugin B has dependency on plugin com.google.lambdaj
  • plugin B has also dependency on plugin A, so it can use its MyClass

lambdaj internally uses the cglib to create proxy classes. So when I have something like this:
Display.getDefault().asyncExec(new Runnable() {
    public void run() {
        MyClass class = Lambda.selectFirst(collection, having(on(MyClass.class).getId(), Matchers.equalTo(id)));
        ....
    }
)};

I get "java.lang.ClassNotFoundException: net.sf.cglib.proxy.Factory". When I debug it and look at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(...),
I can see the plugin that is looking for the net.sf.cglib.proxy.Factory class is the A plugin.

Since I can't modify the com.google.lambdaj plugin, the only workaround was to put Eclipse-BuddyPolicy: global in my A plugin.
This is AFAIK bad solution because it then looks for the class in all exported packages from the whole RCP application.

The fact that my code runs on the SWT Event thread is maybe irrelevant.

[Updated on: Fri, 04 October 2013 04:06]

Report message to a moderator

Re: Class loading in SWT Event Thread [message #1125320 is a reply to message #1125152] Fri, 04 October 2013 07:45 Go to previous messageGo to next message
Thorsten Schlathölter is currently offline Thorsten Schlathölter
Messages: 208
Registered: February 2012
Location: Düsseldorf
Senior Member
Hi,
have you imported the package "net.sf.cglib.proxy" in your A-Bundle? Then it should work. The BuddyPolicy should not be required.

Regards,
Thorsten
Re: Class loading in SWT Event Thread [message #1125377 is a reply to message #1125320] Fri, 04 October 2013 08:54 Go to previous messageGo to next message
Jan Krakora is currently offline Jan Krakora
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
Well, that works indeed. I don't know if it's the best solution, but it's better than the global BuddyPolicy. Thanks
Re: Class loading in SWT Event Thread [message #1125425 is a reply to message #1125377] Fri, 04 October 2013 09:52 Go to previous message
Thorsten Schlathölter is currently offline Thorsten Schlathölter
Messages: 208
Registered: February 2012
Location: Düsseldorf
Senior Member
Yes that is the best solution. It is just how it is supposed to be in OSGI.

Regards,
Thorsten
Previous Topic:Eclipse Fully Dark Theme
Next Topic:Responsive Apps?
Goto Forum:
  


Current Time: Tue Jul 22 21:48:15 EDT 2014

Powered by FUDForum. Page generated in 0.01893 seconds