Return-Path: X-Original-To: apmail-felix-dev-archive@www.apache.org Delivered-To: apmail-felix-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id A77AE7853 for ; Sat, 27 Aug 2011 22:21:03 +0000 (UTC) Received: (qmail 44918 invoked by uid 500); 27 Aug 2011 22:21:03 -0000 Delivered-To: apmail-felix-dev-archive@felix.apache.org Received: (qmail 44801 invoked by uid 500); 27 Aug 2011 22:21:02 -0000 Mailing-List: contact dev-help@felix.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@felix.apache.org Delivered-To: mailing list dev@felix.apache.org Received: (qmail 44792 invoked by uid 99); 27 Aug 2011 22:21:02 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 27 Aug 2011 22:21:02 +0000 X-ASF-Spam-Status: No, hits=-2000.5 required=5.0 tests=ALL_TRUSTED,RP_MATCHES_RCVD X-Spam-Check-By: apache.org Received: from [140.211.11.116] (HELO hel.zones.apache.org) (140.211.11.116) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 27 Aug 2011 22:20:59 +0000 Received: from hel.zones.apache.org (hel.zones.apache.org [140.211.11.116]) by hel.zones.apache.org (Postfix) with ESMTP id E2BECD3E38 for ; Sat, 27 Aug 2011 22:20:37 +0000 (UTC) Date: Sat, 27 Aug 2011 22:20:37 +0000 (UTC) From: "Pierre De Rop (JIRA)" To: dev@felix.apache.org Message-ID: <1931580256.517.1314483637909.JavaMail.tomcat@hel.zones.apache.org> In-Reply-To: <925242163.515.1314482917662.JavaMail.tomcat@hel.zones.apache.org> Subject: [jira] [Commented] (FELIX-3090) SCR factory components ignore reference target filters MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 X-Virus-Checked: Checked by ClamAV on apache.org [ https://issues.apache.org/jira/browse/FELIX-3090?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13092388#comment-13092388 ] Pierre De Rop commented on FELIX-3090: -------------------------------------- It seems that the root cause of the problem comes from the ComponentFactoryImpl.getProperties() method, which does not include the target properties of references in the component properties. Because of that, when the AbstractComponentManager.verifyDependencyManagers method is invoked, it then invoke the DependencyManager.setTargetFilter method with a Property object which does not include the target properties of references ... The following fix sounds to work: in the end of the ComponentFactoryImpl.getProperties() method, just add the following: public Dictionary getProperties() { ...... // add target properties of references List depMetaData = getComponentMetadata().getDependencies(); for ( Iterator di = depMetaData.iterator(); di.hasNext(); ) { ReferenceMetadata rm = ( ReferenceMetadata ) di.next(); if ( rm.getTarget() != null ) { props.put( rm.getTargetPropertyName(), rm.getTarget() ); } } return props; } Felix, can you verify this fix ? thanks. > 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.(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