Hello,

A simple example as this one
(a few lines of SCALA)
shows that the registration of ANY dependent service (here aDep, from the console)
activates the componentFactory service (here "Factory"),
even if it does NOT satisfy the references
of the component (here the  property "Dep=true" required by "Comp").

This is unfortunate, since this may trigger a code which try to instanciate the component service, which will be refused by the SCR, while the factory is activated.


-------------------------------- cut here ------------------------------------------
package test;

import org.osgi.service.component.ComponentFactory
import aQute.bnd.annotation.component.Activate
import aQute.bnd.annotation.component.Component
import aQute.bnd.annotation.component.Reference

@Component (provide=Array())
class Factory {
    var c: Comp = _
    @Reference(target = "(component.factory=Comp)")
      def bind(cf : ComponentFactory ) = { println("Factory bind")
    c = cf.newInstance(null).getInstance().asInstanceOf[Comp];
    println("c is " + c)
      }
  @Activate
  def start()=println("Factory Activate")
}

@Component(factory = "Comp")
class Comp {
    @Reference(target = "(Dep=true)")
    def bind(d: Dep)  = println("Comp.bind")
}

trait Dep {}
@Component(enabled=false, properties=Array("Dep=false"))
class aDep extends Dep


-------------------------------- cut here ------------------------------------------

Is this a bug of the SCR implementation ?

In apparence, yes.
A Component Factory service whose component instance has a dependence on another
component shall be available only when this dependence is resolved.
This is apparently the meaning of chapter 112.5.5 of compendium 4.2, in the first paragraph.

The issue raised about this
https://issues.apache.org/jira/browse/FELIX-309 <https://issues.apache.org/jira/browse/FELIX-3090>
(which provided  the example re-coded here)
has been closed, and marked resolved, which seems wrong.

What could we do or say about that,  please ?

Bye!



Reply via email to