[ 
https://issues.apache.org/jira/browse/FELIX-1131?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12707127#action_12707127
 ] 

Richard S. Hall commented on FELIX-1131:
----------------------------------------

Thinking about this some more, I believe that even though service factories 
were not necessarily intended to address laziness, it is the case that this is 
a major use case nowadays (e.g., iPOJO, DS, etc.), so breaking this by eagerly 
getting the service object would be a mistake.

The use case here is not particularly clear to me, but I would have to almost 
say it is invalid. The situation for the framework is that it needs to try to 
make some sort of good faith guarantee for the client that it won't get a class 
cast exception. It can only do this based on knowledge of the provider and the 
client.

This use case basically hides the provider and wants to get a guarantee from 
the framework that everything will be okay for the client. That doesn't really 
seem possible. Is it possible that bundle C could register the service factory 
using the bundle context of whoever the actual provider is, which does have a 
wire for the package?

> ServiceReference.isAssignableTo fails when using a factory that can not see 
> the exported class and the bundle exporting the service does not have a 
> direct wire to this class
> -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: FELIX-1131
>                 URL: https://issues.apache.org/jira/browse/FELIX-1131
>             Project: Felix
>          Issue Type: Bug
>          Components: Framework
>    Affects Versions: felix-1.6.0
>            Reporter: Guillaume Nodet
>
>  * bundle A defines an interface R and a class S in different packages, whith 
> S implementing R
>  * bundle B defines a class T extending S, it has an import statement on S 
> package, but not on R package
>  * bundle C defines a ServiceFactory that export T service without any import 
> on any package from R, S, T
> in this case, the line 426 of ServiceRegistrationImpl is executed:
>                        allow = 
> getServiceRegistration().isClassAccessible(requestClass);
> which looks like:
>    protected boolean isClassAccessible(Class clazz)
>    {
>        try
>        {
>            // Try to load from the service object or service factory class.
>            Class sourceClass = (m_factory != null)
>                ? m_factory.getClass() : m_svcObj.getClass();
>            Class targetClass = Util.loadClassUsingClass(sourceClass, 
> clazz.getName());
>            return (targetClass == clazz);
>        }
>        catch (Exception ex)
>        {
>            // Ignore this and return false.
>        }
>        return false;
>    }
> So felix checks if the classloader used to load the factory can also load the 
> interface, which is not the case in my example.
> So isClassAccessible returns false and the event is not dispatched to the 
> service listener.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to