[
https://issues.apache.org/jira/browse/FELIX-5956?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Pierre De Rop resolved FELIX-5956.
----------------------------------
Resolution: Fixed
Committed a fix in revision 1843196.
The problem was in the dm runtime ServiceLifecycleHandler.init() mehod, which
was adding the internal toggle to the component *after* the component;init()
method was called.
To fix, the internal toggle associated to the lifecycle runnable object must be
added to the component *before* calling the init method.
> NPE when invoking a lifecycle runnable method from init method
> --------------------------------------------------------------
>
> Key: FELIX-5956
> URL: https://issues.apache.org/jira/browse/FELIX-5956
> Project: Felix
> Issue Type: Bug
> Components: Dependency Manager Runtime
> Affects Versions: org.apache.felix.dependencymanager-r1
> Reporter: Pierre De Rop
> Assignee: Pierre De Rop
> Priority: Major
> Fix For: org.apache.felix.dependencymanager-r12
>
>
> When you use a DM lifecycle controller in order to trigger component
> activation from the @Init method, a NPE is throw if you invoke the lifecylce
> runnable from the init method.
> For example, the following code:
> {code:java}
> @Component
> public class MyServiceImpl implements MyService {
> @LifecycleController
> volatile Runnable _start;
> @Init
> void init() {
> _start.run(); // immediately trigger service activation
> }
> }
> {code}
> produces the following NPE:
> {code}
> Caused by: java.lang.NullPointerException
> at
> org.apache.felix.dm.runtime.ToggleServiceDependency.activate(ToggleServiceDependency.java:49)
> at
> org.apache.felix.dm.runtime.ServiceLifecycleHandler$ComponentStarter.run(ServiceLifecycleHandler.java:431)
> at
> org.apache.felix.dependencymanager.samples.hello.annot.ServiceProviderImpl.init(ServiceProviderImpl.java:47)
> ... 65 more
> {code}
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)