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

Felix Meschberger commented on FELIX-3090:
------------------------------------------

Thanks for proposing the patch. While this may perfectly work, I think it is 
not entirely correct:

(1) The getProperties() method is used to set the service registration 
properties, which I would think are not part of the ComponentFactory service 
registration. Thus adding them might be wrong. On the other hand, they might 
not hurt.

(2) The bigger issue is, that this only gives you part of the rent: A call to 
the newInstance method may provide even more target properties and thus may 
cause the selection to become entirely different. Consider a case where a 
service is registered with name="xyz". The ComponentFactory is predefined with 
target filter name="abc". This causes the ComponentFactory to be unsatisifed 
and not registered. Yet the newInstance method might have been called with a 
target filter name="xyz" thus actually satisifying the reference - but since 
the default prevents satisfaction, the newInstance method will never be called 
....

(3) Theoretically timing may be such that the required service may just be 
unregistered between the user of the ComponentFactory getting the 
ComponentFactory service and calling the newInstance method in which case this 
would be a failure, too. So regardless of whether we do analyze target filters 
for the ComponentFactory registration or not, a ComponentException may be 
thrown on newInstance.

Given the second (and to some degree the third) issue, I am reluctant to such a 
patch.

> SCR factory components ignore reference target filters
> ------------------------------------------------------
>
>                 Key: FELIX-3090
>                 URL: https://issues.apache.org/jira/browse/FELIX-3090
>             Project: Felix
>          Issue Type: Bug
>          Components: Declarative Services (SCR)
>    Affects Versions:  scr-1.6.0
>            Reporter: Pierre De Rop
>
> This issue is described in the following post:
> http://www.mail-archive.com/users@felix.apache.org/msg10925.html
> Basically, when a component is declaring a factory (in order to register a 
> ComponentFactory in the registry), 
> then any extra Reference' target filters are not taken into acount.
> This is a problem because the ComponentFactory is registered in the registry 
> even if some References are not satisfied.
> Consider the following example (It uses the BND SCR annotations):
> @Component(factory = "AFactory")
> public class A {
>     @Reference(name="YDependency", target = "(name=Z)")
>     void bind(Y y) {
>         System.out.println("A.bind(" + y + ")");
>     }
>     @Activate
>     void start() {
>         System.out.println("A.start");
>     }
> }
> public interface Y {
> }
> @Component(properties = { "name=ZZZZZ" })
> public class YImpl implements Y {
> }
> @Component
> public class AFactory {
>     @Reference(target = "(component.factory=AFactory)")
>     void bind(ComponentFactory AFactory) {
>         System.out.println("AFactory.bind(" + AFactory + ")");
>         try {
>             ComponentInstance ci = AFactory.newInstance(null);
>             A a = (A) ci.getInstance();
>             System.out.println("Created " + a);
>         }
>         catch (Throwable t) {
>             t.printStackTrace();
>         }
>     }
> }
> Here, the "YDependency" Reference of the "A" component is not satisfied, but 
> the ComponentFactory for the
> "A" component is somehow registered, and when the "AFactory" component 
> catches it, then it get the following exception,
> when trying to instantiate the "A" component instance:
> org.osgi.service.component.ComponentException: Failed activating component
>         at 
> org.apache.felix.scr.impl.manager.ComponentFactoryImpl.newInstance(ComponentFactoryImpl.java:120)
>         at test.scr.factory.AFactory.bind(AFactory.java:15)
>         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>         at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>         at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>         at java.lang.reflect.Method.invoke(Method.java:597)
>         at 
> org.apache.felix.scr.impl.helper.BaseMethod.invokeMethod(BaseMethod.java:227)
>         at 
> org.apache.felix.scr.impl.helper.BaseMethod.access$1(BaseMethod.java:219)
>         at 
> org.apache.felix.scr.impl.helper.BaseMethod$Resolved.invoke(BaseMethod.java:591)
>         at 
> org.apache.felix.scr.impl.helper.BaseMethod$NotResolved.invoke(BaseMethod.java:548)
>         at 
> org.apache.felix.scr.impl.helper.BaseMethod.invoke(BaseMethod.java:472)
>         at 
> org.apache.felix.scr.impl.manager.DependencyManager.invokeBindMethod(DependencyManager.java:1028)
>         at 
> org.apache.felix.scr.impl.manager.DependencyManager.bind(DependencyManager.java:944)
>         at 
> org.apache.felix.scr.impl.manager.DependencyManager.open(DependencyManager.java:868)
>         at 
> org.apache.felix.scr.impl.manager.ImmediateComponentManager.createImplementationObject(ImmediateComponentManager.java:200)
>         at 
> org.apache.felix.scr.impl.manager.ImmediateComponentManager.createComponent(ImmediateComponentManager.java:118)
>         at 
> org.apache.felix.scr.impl.manager.AbstractComponentManager$Unsatisfied.activate(AbstractComponentManager.java:1013)
>         at 
> org.apache.felix.scr.impl.manager.AbstractComponentManager.activateInternal(AbstractComponentManager.java:333)
>         at 
> org.apache.felix.scr.impl.manager.AbstractComponentManager.enable(AbstractComponentManager.java:157)
>         at 
> org.apache.felix.scr.impl.config.ImmediateComponentHolder.enableComponents(ImmediateComponentHolder.java:313)
>         at 
> org.apache.felix.scr.impl.BundleComponentActivator.loadDescriptor(BundleComponentActivator.java:253)
>         at 
> org.apache.felix.scr.impl.BundleComponentActivator.initialize(BundleComponentActivator.java:147)
>         at 
> org.apache.felix.scr.impl.BundleComponentActivator.<init>(BundleComponentActivator.java:111)
>         at 
> org.apache.felix.scr.impl.Activator.loadComponents(Activator.java:274)
>         at 
> org.apache.felix.scr.impl.Activator.bundleChanged(Activator.java:192)
>         at 
> org.apache.felix.framework.util.EventDispatcher.invokeBundleListenerCallback(EventDispatcher.java:807)
>         at 
> org.apache.felix.framework.util.EventDispatcher.fireEventImmediately(EventDispatcher.java:729)
>         at 
> org.apache.felix.framework.util.EventDispatcher.fireBundleEvent(EventDispatcher.java:610)
>         at org.apache.felix.framework.Felix.fireBundleEvent(Felix.java:3879)
>         at org.apache.felix.framework.Felix.startBundle(Felix.java:1850)
>         at 
> org.apache.felix.framework.Felix.setActiveStartLevel(Felix.java:1192)
>         at 
> org.apache.felix.framework.StartLevelImpl.run(StartLevelImpl.java:266)
>         at java.lang.Thread.run(Thread.java:662)

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to