Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » classloader/thread instanceof problem
classloader/thread instanceof problem [message #501275] Tue, 01 December 2009 17:40 Go to next message
Bob Seamon is currently offline Bob SeamonFriend
Messages: 1
Registered: July 2009
Junior Member
Hi all.

I have a situation where
class Foo {}
...
Foo foo = new Foo();
...
Class<?> someClass = Foo.class;

where
someClass.isInstance(foo)


is returning false.

I also have a similar problem where I have a map that is keyed on Class<?> where requests for map.get(Foo.class) is returning null, even though I can see that there is a key/value pair of Foo.class/someObject in the map.

I have a Main RCP application and a headless RCP application which wraps a REST server.

If I run the headless RCP as a separate application (by its own executable/jvm) I do not have this problem. But if I try to start the headless application from a Command/Handler in the main RCP, the problems arise.

I thought that this was a classLoader problem... and it is I suppose. But the strange thing is that I have several occasions where the classloaders are different instances of org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader, yet they have no problem resolving someClass.isInstance(foo) to true when it is supposed to be true. When someClass.isInstance(foo) is false and its supposed to be true, both class loaders are still instances of DefaultClassLoader.

Also I've noticed that in both cases, launching separately and from a command within the main RCP, that the code executing the server startup is being done from the "main" java.lang.Thread.

So I suppose the big question is what's different about launching the REST server in a stand-alone headless RCP vs. launching the application from within a GUI RCP? And what can be done about getting Class.isInstance to work right?

Re: classloader/thread instanceof problem [message #501631 is a reply to message #501275] Thu, 03 December 2009 08:18 Go to previous messageGo to next message
Michael Golovanov is currently offline Michael GolovanovFriend
Messages: 37
Registered: October 2009
Member
Hi, Bob

I can not reproduce your bug
I am create 2 plugins: test1 and test2
test1 contains RCP application code
and test2 contatins class Foo

At test1 Activator i try to run this code

		
// Create foo for test2 plugin
Foo foo = new Foo();
Class<?> someClass = Foo.class;
System.out.println(someClass.isInstance(foo));


and true was printed as i think.

Can you get more details?
Re: classloader/thread instanceof problem [message #501702 is a reply to message #501275] Thu, 03 December 2009 14:39 Go to previous message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Eclipse runs on top of Equinox, and OSGi implementation. That means that each bundle has its own class loader. Consider this example:

Bundle A exports classes from common.jar, containing Foo

Bundle B depends on A, and creates an instance of Foo

Bundle C depends on A, gets the Foo from B, and does class.isInstance(foo) == true

The failing example:

Bundle B contains common.jar and creates an instance of Foo

Bundle C contains common.jar, gets the Foo from B, and does class.isInstance(foo) == false

You can examine this if you look at both Class instances you are comparing and check their ClassLoaders.

PW


Previous Topic:How to automatically use new Plugins in my RCP 3.5 App
Next Topic:Perspective in editor
Goto Forum:
  


Current Time: Fri Apr 26 19:12:58 GMT 2024

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

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

Back to the top