Hi Massimo,

> Am I doing something which is invalid?

Long story short, annotation inheritance is something that you are strongly 
discouraged from doing.

The DS annotations are not designed to be inherited by child classes, 
technically this is a violation of encapsulation because the DS runtime is 
reflectively calling fields/methods on a super type which is defined in another 
bundle. As DS is allowed to (and normally does) operate on default or private 
visibility members this means that you can end up referencing the private 
internals of another bundle (the one holding the super type) in another bundle 
(the one holding the component). This can then break at runtime if you wire to 
an updated version of the super type which has (for example) changed the name 
of a private field.

If you do want to use inherited annotations across bundles (not a good idea) 
then you can do so by using bnd configuration 
<https://bnd.bndtools.org/instructions/dsannotations-options.html>.

> org.apache.felix.resolver.reason.ReasonException: Unable to resolve root: 
> missing requirement [root] osgi.identity; osgi.identity=FOO; 
> type=karaf.feature; version=0; 
> filter:="(&(osgi.identity=FOO)(type=karaf.feature)(version>=0.0.0))" [caused 
> by: Unable to resolve FOO/0.0.1: missing requirement [FOO/0.0.1] 
> osgi.identity; osgi.identity=FOO; type=osgi.bundle; version="[0.0.1,0.0.1]"; 
> resolution:=mandatory [caused by: Unable to resolve FOO/0.0.1: missing 
> requirement [FOO/0.0.1] osgi.wiring.package; 
> filter:="(&(osgi.wiring.package=org.osgi.service.component)(version>=1.3.0)(!(version>=2.0.0)))”]]

This error is actually not to do with annotation inheritance. Instead the issue 
is that you’re trying to use DS 1.3, but Karaf doesn’t support it.

Tim


> On 17 Dec 2019, at 17:30, Massimo Bono <massimobo...@gmail.com> wrote:
> 
> Hi, 
> 
> I'm developing a bundle which provides an abstract class called 
> "AbstractBundle". Such class uses DS annotation over abstract methods, like:
> 
> @Deactivate
> public abstract void deactivate();
> 
> This leads to the fact that the class imports classes from 
> "org.osgi.service.component". I want to declare this abstract class mainly 
> for allowing developers to automatically implements some important DS methods 
> and for documentation purposes.
> 
> The generated bundles has the correctly Import-Package entry 
> (org.osgi.service.component;version="[1.3,2)"). However, when I try to test 
> its installation in a "KarafTestSupport" derived class (where in the config i 
> install the SCR feature via:
> 
> KarafDistributionOption.features("standard", "scr")
> 
> karaf still complaints about the missing reference. here the error:
> 
> org.apache.felix.resolver.reason.ReasonException: Unable to resolve root: 
> missing requirement [root] osgi.identity; osgi.identity=FOO; 
> type=karaf.feature; version=0; 
> filter:="(&(osgi.identity=FOO)(type=karaf.feature)(version>=0.0.0))" [caused 
> by: Unable to resolve FOO/0.0.1: missing requirement [FOO/0.0.1] 
> osgi.identity; osgi.identity=FOO; type=osgi.bundle; version="[0.0.1,0.0.1]"; 
> resolution:=mandatory [caused by: Unable to resolve FOO/0.0.1: missing 
> requirement [FOO/0.0.1] osgi.wiring.package; 
> filter:="(&(osgi.wiring.package=org.osgi.service.component)(version>=1.3.0)(!(version>=2.0.0)))"]]
> 
> Note that I install the artifact exposing class AbstractBundle via a karaf 
> feature.
> 
> Am I doing something which is invalid?
> 
> Thanks for any kind reply
> 
> -- 
> Ing. Massimo Bono

Reply via email to