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

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

Ok, in your original description it was unclear that it was registering a 
service factory using the context of another bundle. So, yes, what you describe 
is case 2 in isClassAccessible().

Unfortunately, we did have a case where the extender did have access to the 
service package, but it was different than the extendee, but it was still 
expected to inject. In this case, I don't remember if the extender was 
importing or exporting the service package. Consider a simple scenario of a log 
service, the extender may have access to the service, but it is not clear 
whether that should impact which log service the extendee can be injected with.

This is the problem with service factories, we cannot know for certain unless 
we get the service object and check which class it is using.

I feel that if we make the change you are proposing we'll just break the other 
case, so it is a question of which case should we break? Another possibility is 
to aggressively get the service object, but only in case 2.
                
> 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: framework-1.6.0
>            Reporter: Guillaume Nodet
>            Assignee: Richard S. Hall
>         Attachments: FELIX-1131.txt
>
>
>  * 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.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to