FELIX-4350 Fix race between service tracker open and service removed event

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1549728 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 ae4ade4..1ba82f6 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
@@ -942,10 +942,7 @@
         public void removedService( ServiceReference<T> serviceReference, RefPair<T> refPair, int trackingCount )
         {
             m_componentManager.log( LogService.LOG_DEBUG, "dm {0} tracking {1} SingleStatic removed {2} (enter)", new Object[] {getName(), trackingCount, serviceReference}, null );
-            if ( refPair != null ) //TODO needs investigation
-            {
-                refPair.setDeleted( true );
-            }
+            refPair.setDeleted( true );
             this.trackingCount = trackingCount;
             tracked( trackingCount );
             boolean reactivate;
diff --git a/scr/src/main/java/org/apache/felix/scr/impl/manager/ServiceTracker.java b/scr/src/main/java/org/apache/felix/scr/impl/manager/ServiceTracker.java
index fd9b5dc..1cc3eee 100644
--- a/scr/src/main/java/org/apache/felix/scr/impl/manager/ServiceTracker.java
+++ b/scr/src/main/java/org/apache/felix/scr/impl/manager/ServiceTracker.java
@@ -1249,6 +1249,9 @@
                 object = tracked.remove(item); /*                                                 * must remove from tracker before
                                                  * calling customizer callback
                                                  */
+                if (object == null) { /* are we actually tracking the item */
+                    return;
+                }
                 trackingCount = modified(); /* increment modification count */
             }
             if (DEBUG) {