Hi,
I would like to tell you about my experiences that I made yesterday. I had a
error that occurred during integration testing and which is difficult to
understand. But I was able to fix the error. Maybe I can prevent someone
making the same mistake.
I have a Utility-Class which is used by the Felix-Launcher (systembundle) as
well as by some other bundles. This Utility-Class provides some basic
functionality like catching services with interface-casting and error
handling. Since the systembundle can not import packages the Utility-package
has to be embedded to the systembundle. So far so good. At any point of time
I register a number of services by a Bundle A. And at a later point of time
I catch the services by calling ServiceTracker::getServices() in a Bundle B.
public <T> T[] getServices(BundleContext bundlecontext, Class<T> clazz)
{
ServiceTracker st = new ServiceTracker(bundlecontext, clazz.getName(),
null);
st.open();
Object[] objs = st.getServices();
st.close();
try{
return (T[]) objs;
}catch(LinkageError e){
...
}catch(ClassCastException e){
...
}
The service-objects are instanciated by the bundle-ClassLoader of Bundle A.
The array "Object[] objs" (see above) holding the service-instances is
instanciated by the bootstrap-ClassLoader but not by the ClassLoader of
Bundle A. This causes a ClassCastException because of two different
ClassLoaders. Very nasty!
The solution is to use Collection<T> instead of T[].
Regards
Roland
--
View this message in context:
http://apache-felix.18485.x6.nabble.com/ClassCastException-after-isAssignableTo-tp5003252p5004270.html
Sent from the Apache Felix - Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]