[
https://issues.apache.org/jira/browse/FELIX-1131?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13687753#comment-13687753
]
Guillaume Nodet commented on FELIX-1131:
----------------------------------------
My use case is using blueprint which registers service factories on behalf of
the extended bundle.
When using service factories on behalf of other bundles, the extender is
supposed to use the extended bundle context to register the services. If it
doesn't, the class space consistency is lost.
As we can imagine the extender exporting a package and the extended bundle
exporting the same package. If the extender registers a service created for
the extendee on its own bundle context (or the opposite), you'll soon hit a
ClastCastException.
On my patch, it's a short circuit only when the consumer and the provider have
direct visibility (either import or export) on a package. I don't see how
things could go wrong here, because if both see the package, either it's the
same and that's ok, or those are different and the consumer can't see the
service, or one has no visibility and we use additional checks. The use of
service factories is irrelevant here, as we're considering the exposed classes,
not the factory class, and only the consumer and provider exports, not the
possible extender class space.
> 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