[
https://issues.apache.org/jira/browse/FELIX-5213?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Neil Bartlett resolved FELIX-5213.
----------------------------------
Resolution: Not A Bug
> ComponentContext.getServiceReference returns null though service registered
> ---------------------------------------------------------------------------
>
> Key: FELIX-5213
> URL: https://issues.apache.org/jira/browse/FELIX-5213
> Project: Felix
> Issue Type: Bug
> Components: Declarative Services (SCR)
> Affects Versions: scr-2.0.2
> Reporter: Neil Bartlett
>
> In a component that provides a service and is not immediate, the service is
> registered before activation. Therefore the service reference of the
> registered service should be available to the component, from
> ComponentContext.getServiceReference(), during activation. However the
> following code sample throws NPE:
> {code}
> import org.osgi.framework.Constants;
> import org.osgi.framework.ServiceReference;
> import org.osgi.service.component.ComponentContext;
> import org.osgi.service.component.annotations.Activate;
> import org.osgi.service.component.annotations.Component;
> @Component(service = Object.class, property = "name=scrbug")
> public class Example {
> @Activate
> void activate(ComponentContext context) {
> ServiceReference<?> reference = context.getServiceReference();
> System.out.printf("My service ID is %d%n",
> reference.getProperty(Constants.SERVICE_ID));
> }
> }
> {code}
> Note that the service certainly exists, because I have injected it into a
> second component, in order to force activation of the above.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)