FELIX-3729 fix NPE in getServiceReferences, continue with tracking count
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1424310 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 de7403b..c427d09 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
@@ -30,6 +30,7 @@
import java.util.Set;
import java.util.SortedMap;
import java.util.TreeMap;
+import java.util.TreeSet;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
@@ -143,7 +144,7 @@
private volatile int ceiling;
- private final Set<Integer> missing = new HashSet<Integer>( );
+ private final Set<Integer> missing = new TreeSet<Integer>( );
public void setTracker( ServiceTracker<T, RefPair<T>> tracker )
{
@@ -230,9 +231,24 @@
}
ceiling = trackingCount;
}
- if ( missing.isEmpty() )
+ missing.notifyAll();
+ }
+ }
+
+ protected void waitForTracked( int trackingCount )
+ {
+ synchronized ( missing )
+ {
+ while ( ceiling < trackingCount || ( !missing.isEmpty() && missing.iterator().next() < trackingCount))
{
- missing.notifyAll();
+ try
+ {
+ missing.wait( );
+ }
+ catch ( InterruptedException e )
+ {
+ //??
+ }
}
}
}
@@ -997,7 +1013,12 @@
*/
public ServiceReference<T>[] getServiceReferences()
{
- Collection<RefPair<T>> bound = customizerRef.get().getRefs();
+ Customizer<T> customizer = customizerRef.get();
+ if (customizer == null)
+ {
+ return null;
+ }
+ Collection<RefPair<T>> bound = customizer.getRefs();
if ( bound.isEmpty() )
{
return null;