Pierre De Rop created FELIX-6892:
------------------------------------

             Summary: Removing a dependency from a decorator removes the wrong 
copy
                 Key: FELIX-6892
                 URL: https://issues.apache.org/jira/browse/FELIX-6892
             Project: Felix
          Issue Type: Improvement
          Components: Dependency Manager
            Reporter: Pierre De Rop
            Assignee: Pierre De Rop


When a dependency is added to an adapter, aspect or factory component that has 
already been started, DependencyManager gives each instance of that component 
its own copy of the dependency.

When that dependency is later removed from the component, only one copy is 
removed, and from the wrong instance:
* the copy of one instance is stopped through another instance, which does not 
own it. The owner instance silently stops receiving the service, and a 
{{NullPointerException}} is thrown later, when the owner instance is stopped 
and stops this copy a second time;
* the other instances keep their copy, so the dependency is not removed from 
them.

The problem only shows up when the component has at least two instances.

In addition, the copies given to an instance remain referenced by the decorator 
after that instance is removed (adaptee service, bundle or resource gone, 
factory configuration deleted, decorator stopped), together with the stopped 
instance itself.

h3. Example

{code:java}
// Two Device services are registered: the adapter creates two DeviceServlet 
instances.
AdapterComponent adapter = dm.createAdapterComponent()
    .setAdaptee(Device.class, null)
    .setInterface(DeviceServlet.class, null)
    .setImpl(DeviceServletImpl.class);
dm.add(adapter);

// Later: add a dependency to the adapter. Each DeviceServlet instance gets its 
own copy.
ServiceDependency logDep = 
dm.createServiceDependency().setService(LogService.class).setRequired(false);
adapter.add(logDep);

// Later: remove the dependency from the adapter.
adapter.remove(logDep);
{code}

After {{adapter.remove(logDep)}}:
* the first {{DeviceServlet}} instance still has its copy of the {{LogService}} 
dependency;
* the copy of the second instance has been stopped, but the second instance 
still considers it as one of its dependencies and no longer receives the 
{{LogService}};
* when the second instance is stopped, a {{NullPointerException}} is thrown 
while its dependencies are stopped.

h3. Expected behavior

* Removing a dependency from an adapter, aspect or factory component removes it 
from every instance, each instance losing its own copy.
* Once an instance is removed, the decorator no longer references it or its 
dependency copies.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to