FELIX-2955 Fixed the bug by making sure that only dependency managers that still have a valid bundle context are returned.

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1124285 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/dependencymanager/core/src/main/java/org/apache/felix/dm/DependencyManager.java b/dependencymanager/core/src/main/java/org/apache/felix/dm/DependencyManager.java
index 9567714..5b16edf 100644
--- a/dependencymanager/core/src/main/java/org/apache/felix/dm/DependencyManager.java
+++ b/dependencymanager/core/src/main/java/org/apache/felix/dm/DependencyManager.java
@@ -112,11 +112,15 @@
                 WeakReference reference = (WeakReference) iterator.next();
                 DependencyManager manager = (DependencyManager) reference.get();
                 if (manager != null) {
-                    result.add(manager);
+                    try {
+                        manager.getBundleContext().getBundle();
+                        result.add(manager);
+                        continue;
+                    }
+                    catch (IllegalStateException e) {
+                    }
                 }
-                else {
-                    iterator.remove();
-                }
+                iterator.remove();
             }
         }
         return result;