FELIX-979 Prevent bundle event handling after the bundle activator's stop method has terminated

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@758736 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/configadmin/src/main/java/org/apache/felix/cm/impl/ConfigurationManager.java b/configadmin/src/main/java/org/apache/felix/cm/impl/ConfigurationManager.java
index 2fd6b6e..bdd12a1 100644
--- a/configadmin/src/main/java/org/apache/felix/cm/impl/ConfigurationManager.java
+++ b/configadmin/src/main/java/org/apache/felix/cm/impl/ConfigurationManager.java
@@ -142,6 +142,9 @@
 
     // the maximum log level when no LogService is available
     private int logLevel = CM_LOG_LEVEL_DEFAULT;
+    
+    // flag indicating whether BundleChange events should be consumed (FELIX-979)
+    private volatile boolean handleBundleEvents;
 
     public void start( BundleContext bundleContext )
     {
@@ -198,6 +201,7 @@
         }
 
         // register as bundle and service listener
+        handleBundleEvents = true;
         bundleContext.addBundleListener( this );
 
         // get all persistence managers to begin with
@@ -242,6 +246,7 @@
 
         // stop listening for events
         bundleContext.removeBundleListener( this );
+        handleBundleEvents = false;
 
         if ( configurationListenerTracker != null )
         {
@@ -489,7 +494,7 @@
 
     public void bundleChanged( BundleEvent event )
     {
-        if ( event.getType() == BundleEvent.UNINSTALLED )
+        if ( event.getType() == BundleEvent.UNINSTALLED && handleBundleEvents )
         {
             String location = event.getBundle().getLocation();