Guillaume Nodet wrote:
I think the problem is in the R4SearchPolicyCore, line 345.
When the bundle can not be resolved, it throws a ClassNotFoundException.
I think it should rethrow the ResolveException, and the Felix#loadClass
method could catch it, fire the framework event and hide it by sending a
ClassNotFoundException.
If there's no problem, I'll provide a patch asap.

No, that won't work for the reason stated in the comment in the search policy. Further, ResolveException is a checked exception created in the searchpolicy package, which is a specific implementation of a search policy for the module layer. The module layer doesn't know about ResolveExceptions and thus IModule.getClass() does not throw such an exception.

I guess the proper way to achieve what you want would be for loadBundleClass() to try to resolve the bundle before calling IModule.getClass(), that way it can catch the resolve exception and only report the error if necessary.

-> richard


On Dec 20, 2007 4:04 PM, Guillaume Nodet <[EMAIL PROTECTED]> wrote:

When a class can not be loaded, the o.a.f.framework.Felix class sends a
framework event with an ERROR level.
It can be very verbose in some cases: for example when using spring-osgi,
for each spring bean defined, spring tries to load a class names
XxxBeanInfo, where Xxx is the implemenation class name of the loaded spring
bean.
The piece of code is the loadBundleClass method, lines 1452 of the Felix
class:

    protected Class loadBundleClass(FelixBundle bundle, String name)
throws ClassNotFoundException
    {
        Class clazz = bundle.getInfo().getCurrentModule().getClass(name);
        if (clazz == null)
        {
            // Throw exception.
            ClassNotFoundException ex = new ClassNotFoundException(name);

            // The spec says we must fire a framework error.
            fireFrameworkEvent(
                FrameworkEvent.ERROR, bundle,
                new BundleException(ex.getMessage()));

            throw ex;
        }
        return clazz;
    }

Given the comment, I've tried to find what the spec says.  I think the
comment refers to the Bundle.loadClass methods.  Quoting the spec:

If this bundle cannot be resolved, a Framework event of type Frame-
workEvent.ERROR is fired containing a BundleException with details of the
reason this bundle could not be resolved. This method must then throw a
ClassNotFoundException.

My understanding is that the framework event must be fired when the bundle
can not be *resolved*, not each time a class can not be found.  I suppose
such a case could only happen if the bundle has been installed but not yet
resolved and someone is using the loadClass method.  Can someone please
share thoughts on this ?

--
Cheers,
Guillaume Nodet
------------------------
Blog: http://gnodet.blogspot.com/




Reply via email to