Bind settings gotcha

Problem
Updating an Adapter service bundle caused the Core and Data bundles to restart also, despite there being no direct export/import relationships between them.

Exisiting code
The following elided code sample shows the relevant code in the DataSourceManagerImpl class (from the Data component).

Line 13 is correctly specifying that the Adapter services are optionally mapped into adapters. This means that losing the Adapter service would not cause this mapping to unregister the Data component as this mapping is optional.

The problem is line 25 (highlighted). This line binds the bindAdapter callback to the Adapter service. Because this @Bind is missing optional true the Adapter service is unregistered and the bind condition for this callback is no longer satisfied (it is implicitly mandatory) and so the Data component is compelled to also unregister.

Why then did Core also restart? Because the Core component has a mandatory relationship with the Data component. It requires exactly one DataSourceManager, so when the only Data service component is unregistered, so is Core.

Lesson
Be very careful when pairing @Bind methods to @Requires fields that the parameters match and specify the correct behaviour. There is no relationship between these annotations, although it's tempting to think there is. Just because a field is declared optionally mapped to a service this behaviour does not propagate to the bind of the same service, or vice versa.