You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@felix.apache.org by "Felix Meschberger (Reopened) (JIRA)" <ji...@apache.org> on 2012/02/17 12:23:59 UTC

[jira] [Reopened] (FELIX-3090) SCR factory components ignore reference target filters

     [ https://issues.apache.org/jira/browse/FELIX-3090?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Felix Meschberger reopened FELIX-3090:
--------------------------------------


Reopening this issue after reconsidering as of [1]:

(1) Default Target property values are provided by the developer by intent so they probably should be respected (The target properties should still not be used as registration properties as required by Section 112.5.5: "The service properties of the Component Factory service must not include the component properties.").

(2) It is true that a Dictionary object provided to the newInstance method may define different target properties. In this case a the satisfaction criteria for the ComponentFactory service and the desired new instance are in fact different as required by the spec (section 112.5.5 Factory Componet)

[1] http://markmail.org/message/hjks7q2qzz3p6hwn
                
> 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
>            Assignee: Felix Meschberger
>         Attachments: test-scr-factory.tgz, test-scr-factory.tgz
>
>
> 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.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira