Pierre De Rop created FELIX-6885:
------------------------------------
Summary: Stale and duplicate entries in auto-configured
Collection/Map fields
Key: FELIX-6885
URL: https://issues.apache.org/jira/browse/FELIX-6885
Project: Felix
Issue Type: Bug
Components: Dependency Manager
Reporter: Pierre De Rop
Assignee: Pierre De Rop
When a component instance is kept alive while the component goes back to the
"waiting for required dependencies" state, its auto-configured Collection or
Map fields are not kept consistent with the available services. They can
contain services that are no longer available, and the same service can be
injected more than once.
The component instance is kept in this state when one of its dependencies needs
the instance, which is the default for a ConfigurationDependency.
*Example*
{code:java}
dm.add(createComponent()
.setImplementation(MyComponent.class)
.add(createConfigurationDependency().setPid("my.pid"))
.add(createServiceDependency().setService(Foo.class).setRequired(true)));
public class MyComponent {
volatile List<Foo> foos;
void updated(Dictionary<String, ?> conf) { }
void start() {
System.out.println("start: foos = " + foos);
}
}
{code}
Scenario 1 - removed service still injected:
# The configuration "my.pid" is available, Foo1 is registered: start() sees
[Foo1].
# Foo1 is unregistered: the component is stopped, the instance is kept.
# Foo2 is registered: start() sees [Foo1, Foo2].
Scenario 2 - duplicate entries (with another required dependency Bar):
# The configuration, Bar and Foo1 are available: start() sees [Foo1].
# Bar is unregistered, then registered again.
# start() sees [Foo1, Foo1].
The same problem happens with Map<Foo, Dictionary> fields (scenario 1).
*Expected behavior*
When start() is called again, the auto-configured Collection/Map fields only
contain the currently available services, each one once:
* Scenario 1: [Foo2]
* Scenario 2: [Foo1]
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)