bnd icon indicating copy to clipboard operation
bnd copied to clipboard

Analyzer.findProvidedPackages only considers implemented provider interfaces but not extended provider classes

Open kwin opened this issue 2 years ago • 11 comments

The ProviderType annotation may be applied to classes, interfaces and packages. While for interfaces the relation which needs to be checked is the "implements" relation, for classes it is the "extends" relation. But in https://github.com/bndtools/bnd/blob/d06df066f402f1433b70c51f568c40a444b4518d/biz.aQute.bndlib/src/aQute/bnd/osgi/Analyzer.java#L2153 only the interfaces being implemented are checked if they are a provider type. The super class (i.e. the "extension" relation) is not considered. That may lead to incorrect import-package version ranges.

kwin avatar Dec 05 '23 19:12 kwin

I think you ran into my very old dislike for inheritance in API, especially inheritance to a class in another package ... begging for problems.

This is very hot code so I am a bit hesitant to just add the super class, but it does seem to make sense for the poor souls having to live with heavy inheritance based APIs.

@bjhargrave as the only person I trust in this topic, can you take a look and tell me if you see problems?

pkriens avatar Dec 07 '23 11:12 pkriens

It should probably also include the super class in the result if the super class is ProviderType. But it basically almost never makes sense to mark a non-interface class as ProviderType unless the class has protected methods which only a subclass could invoke.

Also, I think there is an issue in

https://github.com/bndtools/bnd/blob/4d1c6b08957f853691d906113414d657db91e6ea/biz.aQute.bndlib/src/aQute/bnd/osgi/Analyzer.java#L2173-L2186

since it does not appear to handle the case where the package containing the type is marked ProviderType.

bjhargrave avatar Dec 07 '23 13:12 bjhargrave

since it does not appear to handle the case where the package containing the type is marked ProviderType. Interesting ... I did not know we support the package for the ProviderType ...

pkriens avatar Dec 07 '23 15:12 pkriens

I did not know we support the package for the ProviderType ...

https://github.com/osgi/bugzilla-archive/issues/2774

kwin avatar Dec 07 '23 15:12 kwin

osgi/bugzilla-archive#2774

Ha! I love that this bugzilla archive is still useful.

bjhargrave avatar Dec 07 '23 15:12 bjhargrave

But it basically almost never makes sense to mark a non-interface class as ProviderType unless the class has protected methods which only a subclass could invoke.

I think often these are abstract classes extending from an interface being provided centrally, from which different provider bundles just inherit their own implementation.

kwin avatar Dec 07 '23 16:12 kwin

... inherit their own implementation

And that is why it should never be API ... Fine for provider bundles, but in API it sucks majorly.

pkriens avatar Dec 08 '23 08:12 pkriens

Just to have a reference: This seems to be related to this issue here: https://github.com/osgi/osgi/issues/643

juergen-albert avatar Dec 08 '23 16:12 juergen-albert

@juergen-albert Could be related but https://github.com/osgi/osgi/issues/643 is broader as it is about multiple levels of inheritance as well.

kwin avatar Dec 08 '23 17:12 kwin

@tbitonti any progress? If you're having a hard time let me know. If necessary I can take this over.

pkriens avatar Jan 23 '24 16:01 pkriens

@tbitonti if you can't work on this, please unassign yourself. It has been open for two months now and I want this closed.

pkriens avatar Feb 13 '24 07:02 pkriens

@tbitonti last chance ... I'll take his over next week if nothing happens

pkriens avatar Mar 15 '24 09:03 pkriens

Fixed in #6055

pkriens avatar Mar 18 '24 14:03 pkriens