During 'Bundelization' of the JacORB CORBA library I encountered a
problem already seen when using log4j as a:

Libraries that load classes by name often use the thread context
classoader for loading. I guess, this due to the fact that it's often
necessary to pass a special classloader into the library. Indeed, within
felix this is needed in some circumstances. E.g., to get an ORB instance
one calls org.omg.CORBA.ORB.init(). This method (part of the standard
java runtime) reads the actual name of the class that implements an
ORB-factory from a system property , and then uses the thread context
classloader to instantiate the factory. When ORB.init() is called from a
bundle-activator, and the system properties state that JacORB should be
used as ORB-Factory, this fails, even if the bundle under activation has
a correct Import-Package statement for the jacorb bundle.

The problem is, that the thread-context-classloader in effect when
bundles are activated is NOT the classloader of the module, but the
standard Application Class Loader. I could fix the problem with this
code:

Thread.currentThread().setContextClassLoader( 
   org.jacorb.orb.ORB.class.getClassLoader());

This sets the context class loader to the class loader of the bundle
being activated, and ORB.init() succeeds now.

A very similar problem arises when using the log4j bundle with custom
loglevel classes. These classes are instantiated by the thread context
classloader during log4j initialization, what fails if the thread
context class loader has not been set to the bundle classloader.


Finally, here comes my suggestion:

Wouldn't it make sense to always set the thread context classloader to
the bundle-classloader within the framework before calling
BundleActivator.start() and BundleActivator.stop()? If this does not
violate the OSGi standard, I'd suggest to add this (perhaps
configurable) to the felix framework code.

Kind regards, Martin


 
************************************************
The information contained in, or attached to, this e-mail, may contain 
confidential information and is intended solely for the use of the individual 
or entity to whom they are addressed and may be subject to legal privilege.  If 
you have received this e-mail in error you should notify the sender immediately 
by reply e-mail, delete the message from your system and notify your system 
manager.  Please do not copy it for any purpose, or disclose its contents to 
any other person.  The views or opinions presented in this e-mail are solely 
those of the author and do not necessarily represent those of the company.  The 
recipient should check this e-mail and any attachments for the presence of 
viruses.  The company accepts no liability for any damage caused, directly or 
indirectly, by any virus transmitted in this email.
************************************************

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@felix.apache.org
For additional commands, e-mail: users-h...@felix.apache.org

Reply via email to