Add a workaround for a cornercase where service factories expect the usage to still be there while ungetting the service object
@@ -470,10 +470,21 @@ public class ServiceRegistry
if (usage.m_count.get() <= 0)
{
if (usage.m_svcHolderRef.compareAndSet(holder, null))
+ {
+ // Temporarily increase the usage again so that the
+ // service factory still sees the usage in the unget
+ usage.m_count.incrementAndGet();
+ try
{
// Remove reference from usages array.
((ServiceRegistrationImpl.ServiceReferenceImpl) ref)
.getRegistration().ungetService(bundle, svc);
+ }
+ finally
+ {
+ // now we can decrease the usage again
+ usage.m_count.decrementAndGet();
+ }
}
}
