classloader/thread instanceof problem [message #501275] |
Tue, 01 December 2009 12:40  |
Eclipse User |
|
|
|
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 #501702 is a reply to message #501275] |
Thu, 03 December 2009 09:39  |
Eclipse User |
|
|
|
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
|
|
|
Powered by
FUDForum. Page generated in 0.26735 seconds