[osgi-dev] Classloading Question

David M Williams david_williams at us.ibm.com
Mon Jan 29 13:07:30 EST 2007

You might read bug 167695 to see if it helps


It might help with some practical advise specifically related to xml 
not sure it answers your spec questions. 

Andrew Eberbach/Durham/IBM at IBMUS 
Sent by: osgi-dev-bounces at www2.osgi.org
01/29/2007 12:20 PM
Please respond to
OSGi Developer Mail List <osgi-dev at www2.osgi.org>

osgi-dev at bundles.osgi.org

[osgi-dev] Classloading Question


I'm currently battling a classloading problem. I'm in Eclipse (Equinox) 
and I'm trying to load some XML classes. Now, the classes in question are 
from javax.xml and there is a xerces2.8 bundle that is in the dependency 
list. One of the classes tries to load a javax.xml class and gets a 
ClassCastException. I turn on -verbose:class and see that the class in 
question is being loaded by both the System class loader and the xerces 
bundle Classloader and at some point an interface and a implementation are 

put together and the thing fails. Now if I set the bootdelegation system 
property to javax.xml.* and org.apache.xerces.* everything is loaded from 
the system classloader but I get an IncompatibleClassChange error since 
I'm guessing the classes were compiled against a different version. 

So I've been going through the spec and I'm a little confused about the 
flow for classloading. Figure 24, page 56 of the R4 spec. In java, in 
general, the parent is consulted before anyone else. This is not the case 
in OSGi, right? But, the parent can be consulted if that system property 
is set and the class matches one of the package patterns. So this implies 
to me that even though the bundle got something from the parent. But I 
looked at the bundles and saw that they don't do any non-bundle dependency 

classloading that would make it do a wire load or something like that. So 
then I'm looking through the system properties and I find:


(more info here: 

So is it the case that it tries to load some class, can't find it and then 

falls through to this non-standard behaviour? At that point it gets a 
different version of the class from the parent, tries to match the 
interface to the class and gets the class cast exception?

Finally, I'm curious about secion 3.8.5 about the parent classloader. It 
says that there's a system property that shows which packages are exported 

from Bundle 0. I looked at this list and javax.xml is in there. Is this 
only there for symmetry reasons so that if a bundle imports a package (via 

Import-Package, instead of depending on a specific bundle) that the system 

bundle can expose these non java.* classes as a possible exporter? 


Andrew Eberbach
Autonomic Computing
(919) 254-2645
T/L: 444-2645
aeberbac at us.ibm.com
OSGi Developer Mail List
osgi-dev at www2.osgi.org

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www2.osgi.org/pipermail/osgi-dev/attachments/20070129/e57bf969/attachment.html

More information about the osgi-dev mailing list