ServiceTracker sometimes misses services?

I have an OSGi service tracker with a filter. I noticed that there’s a service that it misses (‘addingService’ is not called). When I use the services command in my osgi (equinox) shell, with the filter that the tracker uses, the missed service is returned.


It turns out that in Equinox, the chain to ServiceTracker#addingService goes through a check BundleContextImpl#isAssignableTo with the reference to the service. This checks if the classes of the reference are wired for the same source (jar) in the listening bundle.

In my case, trying to get the source of the class that the service implements from the reference resulted in null. The reason was that the service was actually created by a class from a third bundle (that class called a method in the registering bundle and used the return value to create the service).

Adding an import for the package in question solved this issue

Leave a Reply

Your email address will not be published. Required fields are marked *