You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by pa...@apache.org on 2017/02/10 12:01:23 UTC

svn commit: r1782455 - /felix/trunk/framework/src/main/java/org/apache/felix/framework/ServiceRegistry.java

Author: pauls
Date: Fri Feb 10 12:01:23 2017
New Revision: 1782455

URL: http://svn.apache.org/viewvc?rev=1782455&view=rev
Log:
Add a workaround for a cornercase where service factories expect the usage to still be there while ungetting the service object (FELIX-5485).

Modified:
    felix/trunk/framework/src/main/java/org/apache/felix/framework/ServiceRegistry.java

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/ServiceRegistry.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/ServiceRegistry.java?rev=1782455&r1=1782454&r2=1782455&view=diff
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/ServiceRegistry.java (original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/ServiceRegistry.java Fri Feb 10 12:01:23 2017
@@ -471,9 +471,20 @@ public class ServiceRegistry
                         {
                             if (usage.m_svcHolderRef.compareAndSet(holder, null))
                             {
-                                // Remove reference from usages array.
-                                ((ServiceRegistrationImpl.ServiceReferenceImpl) ref)
-                                    .getRegistration().ungetService(bundle, svc);
+                            	// 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();
+                            	}
 
                             }
                         }