FELIX-2231 Prevent NullPointerException and uncaught IllegalStateException if bundle has been stopped while the component is being started

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@927394 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/scr/src/main/java/org/apache/felix/scr/impl/manager/DependencyManager.java b/scr/src/main/java/org/apache/felix/scr/impl/manager/DependencyManager.java
index b8a71bd..54c9b79 100644
--- a/scr/src/main/java/org/apache/felix/scr/impl/manager/DependencyManager.java
+++ b/scr/src/main/java/org/apache/felix/scr/impl/manager/DependencyManager.java
@@ -29,6 +29,7 @@
 
 import org.apache.felix.scr.Component;
 import org.apache.felix.scr.Reference;
+import org.apache.felix.scr.impl.BundleComponentActivator;
 import org.apache.felix.scr.impl.helper.BindMethod;
 import org.apache.felix.scr.impl.helper.UnbindMethod;
 import org.apache.felix.scr.impl.helper.UpdatedMethod;
@@ -570,11 +571,29 @@
     {
         if ( hasGetPermission() )
         {
+            // component activator may be null if disposed concurrently
+            BundleComponentActivator bca = m_componentManager.getActivator();
+            if ( bca == null )
+            {
+                return null;
+            }
+
+            // get bundle context, may be null if component deactivated since getting bca
+            BundleContext bc = bca.getBundleContext();
+            if ( bc == null )
+            {
+                return null;
+            }
+
             try
             {
-                return m_componentManager.getActivator().getBundleContext().getServiceReferences(
+                return bc.getServiceReferences(
                     m_dependencyMetadata.getInterface(), targetFilter );
             }
+            catch ( IllegalStateException ise )
+            {
+                // bundle context is not valid any longer, cannot log
+            }
             catch ( InvalidSyntaxException ise )
             {
                 m_componentManager.log( LogService.LOG_ERROR, "Unexpected problem with filter ''{0}''", new Object[]