|
Re: Class Cast Exception for same class [message #672434 is a reply to message #672353] |
Sat, 21 May 2011 02:16 |
Ryan Messages: 17 Registered: May 2011 |
Junior Member |
|
|
Hey, I think you're facing the same problem with classes that I am in another thread that we've been talking in. We both have the problem that a class loaded in one bundle is not the same as exactly the same class loaded in another bundle. You seem to be under the impression that if bundle A and bundle B both import package com.foo from bundle C, then any class in com.foo will be the same class in bundle A as in bundle B, but I'm fairly certain that's not how it works. OSGi is all about letting each bundle live in its own little world, and to the best of my knowledge, it does that by giving each one its own classloader. The same class loaded in two different classloaders will *never* be the same class, either by .equals(), by an instanceof check, a Class.isAssignableFrom, or in casting. It's just the way Java is designed. I'm thinking that a way to solve it--perhaps *the* way to solve it--might be with the Bundle.loadClass method, which lets you choose the bundle, and thereby the classloader, that will load a class. I'm not sure I've got my head all the way around this problem yet, though. It's a tricky one.
|
|
|
Re: Class Cast Exception for same class [message #672452 is a reply to message #672434] |
Sat, 21 May 2011 04:11 |
Ryan Messages: 17 Registered: May 2011 |
Junior Member |
|
|
Some testing appears to show that my previous post was wrong, which is probably good news for both of us. I created a bundle-A, bundle-B, and bundle-C, where C defines type Foo, B defines service FooCreator, and A uses the FooCreator service to get a Foo. I created or obtained the Foo class in several different ways in bundle-A. I got a Foo from the FooCreator service and called getClass(), I used Foo.class, and I used Class.forName(). No matter which way I did it, it always showed that the classloader for class Foo was that of bundle-C. What that says to me is that we each have a class that's being exported by at least two different bundles, and somehow, two different users of that class are loading it from two different places. You might try to get a look at the classloaders of both of your ResteasyProviderFactory classes to see where each is coming from. That might give you an idea of where to look.
|
|
|
Re: Class Cast Exception for same class [message #672576 is a reply to message #672452] |
Sat, 21 May 2011 21:43 |
|
You may use the class loading commands that the milestones of Virgo 3.0 provide. Using "clload" should give you the origin of the class.
More documentation on the commands and some examples can be found in the User Guide
Since you have ClassCast there should be 2 loaders that have as a resource the same class. For example this might happen if you packaged in your bundle a class that is exported by another bundle.
|
|
|
|
Powered by
FUDForum. Page generated in 0.03486 seconds