Skip to content

DS: Bail out when multiple constructors found with the same amount of activation object/static reference arguments #7084

@kwin

Description

@kwin

In DS only one constructor may have the @Activate annotation. However this is only evaluated at compile time and for constructors only leads to generating the init attribute in the component descriptor.
If you have multiple public constructors taking the same amount of parameters (and all having a type which is potentially valid for constructor injection) an arbitrary one may be chosen by DS implementations. Compare with

https://docs.osgi.org/specification/osgi.cmpn/8.0.0/service.component.html#service.component-constructor.injection

If more than one constructor remains, this implies the constructor is overloaded and SCR may choose any of the remaining constructors to construct the component instance.

This should at least lead to a WARNING with bnd as this may lead to subtle bugs which are hard to trace down.

Example:

@Component
public class TestComponent {

    public TestComponent(BundleContext context) {
        
    }
    @Activate
    public TestComponent(Map<String, Object> properties) {
        
    }
    
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions