Do not acquire bundle lock for removing a listner. (FELIX-2924)


git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1095714 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/framework/src/main/java/org/apache/felix/framework/BundleContextImpl.java b/framework/src/main/java/org/apache/felix/framework/BundleContextImpl.java
index ba6f632..e425c91 100644
--- a/framework/src/main/java/org/apache/felix/framework/BundleContextImpl.java
+++ b/framework/src/main/java/org/apache/felix/framework/BundleContextImpl.java
@@ -203,9 +203,10 @@
     {
         checkValidity();
 
-        // CONCURRENCY NOTE: This is a NOT a check-then-act situation,
-        // because internally the framework acquires the bundle state
-        // lock to ensure state consistency.
+        // CONCURRENCY NOTE: This is a check-then-act situation,
+        // but we ignore it since the time window is small and
+        // the result is the same as if the calling thread had
+        // won the race condition.
 
         Object sm = System.getSecurityManager();
 
@@ -249,9 +250,10 @@
     {
         checkValidity();
 
-        // CONCURRENCY NOTE: This is a NOT a check-then-act situation,
-        // because internally the framework acquires the bundle state
-        // lock to ensure state consistency.
+        // CONCURRENCY NOTE: This is a check-then-act situation,
+        // but we ignore it since the time window is small and
+        // the result is the same as if the calling thread had
+        // won the race condition.
 
         m_felix.removeServiceListener(m_bundle, l);
     }
@@ -271,9 +273,10 @@
     {
         checkValidity();
 
-        // CONCURRENCY NOTE: This is a NOT a check-then-act situation,
-        // because internally the framework acquires the bundle state
-        // lock to ensure state consistency.
+        // CONCURRENCY NOTE: This is a check-then-act situation,
+        // but we ignore it since the time window is small and
+        // the result is the same as if the calling thread had
+        // won the race condition.
 
         m_felix.removeFrameworkListener(m_bundle, l);
     }
diff --git a/framework/src/main/java/org/apache/felix/framework/Felix.java b/framework/src/main/java/org/apache/felix/framework/Felix.java
index 6062f97..9073acf 100644
--- a/framework/src/main/java/org/apache/felix/framework/Felix.java
+++ b/framework/src/main/java/org/apache/felix/framework/Felix.java
@@ -2747,25 +2747,7 @@
 
     void removeBundleListener(BundleImpl bundle, BundleListener l)
     {
-        // Acquire bundle lock.
-        try
-        {
-            acquireBundleLock(bundle, Bundle.STOPPING | Bundle.ACTIVE);
-        }
-        catch (IllegalStateException ex)
-        {
-            throw new IllegalStateException(
-                "Can only remove listeners while bundle is active or activating.");
-        }
-
-        try
-        {
-            m_dispatcher.removeListener(bundle, BundleListener.class, l);
-        }
-        finally
-        {
-            releaseBundleLock(bundle);
-        }
+        m_dispatcher.removeListener(bundle, BundleListener.class, l);
     }
 
     /**
@@ -2844,28 +2826,8 @@
     **/
     void removeServiceListener(BundleImpl bundle, ServiceListener l)
     {
-        // Acquire bundle lock.
-        try
-        {
-            acquireBundleLock(bundle, Bundle.STOPPING | Bundle.ACTIVE);
-        }
-        catch (IllegalStateException ex)
-        {
-            throw new IllegalStateException(
-                "Can only remove listeners while bundle is active or activating.");
-        }
-
-        ListenerHook.ListenerInfo listener;
-
-        try
-        {
-            listener =
-                m_dispatcher.removeListener(bundle, ServiceListener.class, l);
-        }
-        finally
-        {
-            releaseBundleLock(bundle);
-        }
+        ListenerHook.ListenerInfo listener =
+            m_dispatcher.removeListener(bundle, ServiceListener.class, l);
 
         if (listener != null)
         {
@@ -2905,25 +2867,7 @@
 
     void removeFrameworkListener(BundleImpl bundle, FrameworkListener l)
     {
-        // Acquire bundle lock.
-        try
-        {
-            acquireBundleLock(bundle, Bundle.STOPPING | Bundle.ACTIVE);
-        }
-        catch (IllegalStateException ex)
-        {
-            throw new IllegalStateException(
-                "Can only remove listeners while bundle is active or activating.");
-        }
-
-        try
-        {
-            m_dispatcher.removeListener(bundle, FrameworkListener.class, l);
-        }
-        finally
-        {
-            releaseBundleLock(bundle);
-        }
+        m_dispatcher.removeListener(bundle, FrameworkListener.class, l);
     }
 
     /**