Pierre De Rop created FELIX-6887:
------------------------------------

             Summary: Copy constructors of ServiceDependency and 
ConfigurationDependency drop fields
                 Key: FELIX-6887
                 URL: https://issues.apache.org/jira/browse/FELIX-6887
             Project: Felix
          Issue Type: Bug
          Components: Dependency Manager
            Reporter: Pierre De Rop
            Assignee: Pierre De Rop


When DependencyManager duplicates a dependency through {{createCopy()}}, some 
of the original dependency's configuration is lost in the copy.

Copies are created in these cases:
* extra dependencies of adapters, aspects, factory components and 
bundle/resource adapters ({{FilterComponent.copyDependencies}})
* clones of PROTOTYPE/BUNDLE scoped components 
({{ComponentImpl.FactoryBase.getService}})
* {{AbstractDecorator.addDependency}}

The copy constructors of two classes do not copy all fields:
* {{ServiceDependencyImpl}}: the {{swap}} callback ({{m_swap}}) is not copied.
* {{ConfigurationDependencyImpl}}: the {{optional}} flag ({{m_optional}}) is 
not copied, so the copy is always required, even if the original was declared 
with {{setRequired(false)}}.

h3. Example

{code:java}
public class Activator extends DependencyActivatorBase {
    @Override
    public void init(BundleContext ctx, DependencyManager dm) throws Exception {
        // One Adapter instance is created for each Foo service
        Component adapter = createAdapterService(Foo.class, null)
            .setImplementation(Adapter.class)
            .setInterface(Bar.class.getName(), null)
            .add(
                // (1) extra service dependency with a swap callback
                createServiceDependency()
                    .setService(Baz.class)
                    .setRequired(true)
                    .setCallbacks("add", "change", "remove", "swap"))
            .add(
                // (2) extra optional configuration dependency
                createConfigurationDependency()
                    .setPid("my.pid")
                    .setRequired(false));
        dm.add(adapter);
    }
}

public class Adapter implements Bar {
    void add(Baz baz)              { System.out.println("add " + baz); }
    void remove(Baz baz)           { System.out.println("remove " + baz); }
    void swap(Baz old, Baz newBaz) { System.out.println("swap"); }
    void updated(Dictionary<String, ?> conf) { }
}
{code}

h3. Actual behavior

# A {{Foo}} service and a {{Baz}} service are published, then an aspect is 
registered on {{Baz}}. Each {{Adapter}} instance logs {{add}} followed by 
{{remove}}. {{swap}} is never called, because the copy of the service 
dependency has no {{swap}} callback.
# A {{Foo}} service is published, but no {{my.pid}} configuration exists. The 
{{Adapter}} instance never starts, because its copy of the configuration 
dependency is required.

h3. Expected behavior

# {{swap}} is invoked on each {{Adapter}} instance when the aspect is inserted.
# The {{Adapter}} instance starts without the {{my.pid}} configuration, and 
{{updated(null)}} is called.



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

Reply via email to