Details
-
Bug
-
Status: Resolved
-
Major
-
Resolution: Invalid
-
scr-2.0.2, maven-bundle-plugin-3.0.1
-
None
-
None
Description
When annotating a field like below with bind and unbind I don't expect SCR to act on the field directly but using named bind and unbind methods instead (which is the case indeed).
@Reference( service = FooService.class, cardinality = ReferenceCardinality.AT_LEAST_ONE, policy = ReferencePolicy.DYNAMIC, bind = "addFooService", unbind = "removeFooService" ) private final Set<FooService> fooServices = new LinkedHashSet<FooService>(); protected synchronized void addFooService(final FooService fooService) { fooServices.add(fooService); // operate on fooServices } protected synchronized void removeFooService(final FooService fooService) { fooServices.remove(fooService); // operate on fooServices }
Nevertheless SCR logs errors at runtime when binding services:
[...] | ERROR | xFrameworkWiring | [...] | [[...]] Field fooServices in component class [...] must be declared volatile to handle a dynamic reference [...] | ERROR | xFrameworkWiring | [...] | [[...]] Field fooServices in component class [...] has unsupported type java.util.Set. It must be one of java.util.Collection or java.util.List. [...] | ERROR | xFrameworkWiring | [...] | [[...]] Field fooServices in component class [...] must not be declared as final
The reference in SCR Component descriptor contains the attribute field (which is likely the cause for the errors):
<reference name="fooServices" cardinality="1..n" policy="dynamic" interface="FooService" bind="addFooService" unbind="removeFooService" field="fooServices"/>
If the combination of reference attributes as above is illegal, Maven Bundle Plugin should log the errors at compile time instead and break the build.
Attachments
Issue Links
- is related to
-
FELIX-4586 A field must be volatile if methods are generated for a dynamic reference
- Closed
-
FELIX-4957 [DS][RFC-212] Various issues with field references
- Closed