Sahoo, Dieter, Yeah, this is what I'm suspecting and I'll try what you suggest, Deiter, to print them out and I think I/we'll know the answer -- they were loaded in two different class loaders... Note that they are from the same package -- I built everything so everything is on the same page from a compile/jar standpoint.
My parent is what creates the Felix container, so it is technically not in a bundle, but I loaded the same class code in it's jar (since I'm going to be using it, of course) -- although, design wise, I'm using the <<interface>> not the <<Impl>>, but I short circuited the interface just to get to the bottom of the riddle... I don't exactly understand the rest of the questions enough to give a technically sufficient response... [sorry]... I'll post back the output of the debug statements as Dieter suggests in a few... As always, much appreciative, Craig -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Sahoo Sent: Tuesday, July 08, 2008 12:26 PM To: [email protected] Subject: Re: brain teaser - embedded felix / class cast exception That basically means the same named class has been defined by two different class loaders. Can you check if the bundle that's exporting the service and the bundle that's consuming the service are not wired to the same org.craig.cache package? Which bundle is exporting the above package? How are the service producer and consumer bundles specifying their package dependency for the above bundle? Thanks, Sahoo Craig Phillips wrote: > Hi, > > Can't cast a class to it's own type... Huh? I just got to believe it's > some kind of class loader thing going on... I really could use a pair of > eyes from one of the class loader experts out there, I anticipate (I > brought other eyes nearby to look, they're stumped too)... Thanks, > Craig Phillips > > Here's the stack error message: > > java.lang.ClassCastException: org.craig.cache.CacheServiceMain cannot be > cast to org.craig.cache.CacheServiceMain > > Here's the line of code: > > CacheServiceMain cacheServiceMain = (CacheServiceMain) bc.getService(sr) > > Here's the context snippet, that creates the felix container, more or > less: > > System.getProperties().setProperty(Main.CONFIG_PROPERTIES_PROP, > > "file:../webapps/craigbox/WEB-INF/felix_config.properties"); > Main.loadSystemProperties(); > Properties configProps = Main.loadConfigProperties(); > List<AutoActivator> list = new ArrayList<AutoActivator>(); // pass > through > list.add(new AutoActivator(configProps)); // pass through > Map map = new StringMap(configProps, false); // pass through > felix = new Felix(map, list); // there isn't a default constructor > felix.start(); > BundleContext bc = felix.getBundleContext(); > ServiceReference sr = > bc.getServiceReference("org.craig.cache.api.CacheServiceMainApi"); > if (sr != null) > { > CacheServiceMain cacheServiceMain = (CacheServiceMain) > bc.getService(sr); > ... // and the rest, which of course doesn't come in to play > > > PS - To Karl -- As you can tell, I have not done the "set TCL to null", > but this is in the "parent" code... Note that I do have all the classes > in the parent dot.jar file, if that's any consolation... > > >
