FELIX-2231 Prevent IllegalStateException and potential NullPointerException when handling a configuration event (the bundle owning the component may have been stopped concurrently)

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@927397 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/scr/src/main/java/org/apache/felix/scr/impl/config/ConfigurationComponentRegistry.java b/scr/src/main/java/org/apache/felix/scr/impl/config/ConfigurationComponentRegistry.java
index 88060e6..01976af 100644
--- a/scr/src/main/java/org/apache/felix/scr/impl/config/ConfigurationComponentRegistry.java
+++ b/scr/src/main/java/org/apache/felix/scr/impl/config/ConfigurationComponentRegistry.java
@@ -157,26 +157,45 @@
                     break;
 
                 case ConfigurationEvent.CM_UPDATED:
-                    final BundleContext bundleContext = cm.getActivator().getBundleContext();
+                    final BundleComponentActivator activator = cm.getActivator();
+                    if ( activator == null )
+                    {
+                        break;
+                    }
+
+                    final BundleContext bundleContext = activator.getBundleContext();
+                    if ( bundleContext == null )
+                    {
+                        break;
+                    }
+
                     final ServiceReference caRef = bundleContext.getServiceReference( ConfigurationAdmin.class
                         .getName() );
                     if ( caRef != null )
                     {
-                        final ConfigurationAdmin ca = ( ConfigurationAdmin ) bundleContext.getService( caRef );
-                        if ( ca != null )
+                        try
                         {
-                            try
+                            final ConfigurationAdmin ca = ( ConfigurationAdmin ) bundleContext.getService( caRef );
+                            if ( ca != null )
                             {
-                                final Dictionary dict = getConfiguration( ca, pid, bundleContext.getBundle().getLocation() );
-                                if ( dict != null )
+                                try
                                 {
-                                    cm.configurationUpdated( pid, dict );
+                                    final Dictionary dict = getConfiguration( ca, pid, bundleContext.getBundle()
+                                        .getLocation() );
+                                    if ( dict != null )
+                                    {
+                                        cm.configurationUpdated( pid, dict );
+                                    }
+                                }
+                                finally
+                                {
+                                    bundleContext.ungetService( caRef );
                                 }
                             }
-                            finally
-                            {
-                                bundleContext.ungetService( caRef );
-                            }
+                        }
+                        catch ( IllegalStateException ise )
+                        {
+                            // If the bundle has been stopped conurrently
                         }
                     }
                     break;