We cannot call stop() on fragments, so make sure the bundle is active
before stopping it. (FELIX-820)


git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@728287 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/framework/src/main/java/org/apache/felix/framework/Felix.java b/framework/src/main/java/org/apache/felix/framework/Felix.java
index 5570ce5..a5f52ed 100644
--- a/framework/src/main/java/org/apache/felix/framework/Felix.java
+++ b/framework/src/main/java/org/apache/felix/framework/Felix.java
@@ -1188,7 +1188,7 @@
                     }
                 }
                 // Stop the bundle if necessary.
-                else if ((impl.getInfo().getPersistentState() == Bundle.ACTIVE) &&
+                else if ((impl.getInfo().getState() == Bundle.ACTIVE) &&
                     (impl.getInfo().getStartLevel(getInitialBundleStartLevel())
                         > m_activeStartLevel))
                 {
@@ -1327,8 +1327,9 @@
                         startBundle(impl, false);
                     }
                     // Stop the bundle if necessary.
-                    else if (impl.getInfo().getStartLevel(getInitialBundleStartLevel())
-                        > m_activeStartLevel)
+                    else if ((impl.getInfo().getState() == Bundle.ACTIVE) &&
+                        (impl.getInfo().getStartLevel(getInitialBundleStartLevel())
+                        > m_activeStartLevel))
                     {
                         stopBundle(impl, false);
                     }
@@ -2173,13 +2174,16 @@
         // The spec says that uninstall should always succeed, so
         // catch an exception here if stop() doesn't succeed and
         // rethrow it at the end.
-        try
+        if (info.getState() == Bundle.ACTIVE)
         {
-            stopBundle(bundle, true);
-        }
-        catch (BundleException ex)
-        {
-            fireFrameworkEvent(FrameworkEvent.ERROR, bundle, ex);
+            try
+            {
+                stopBundle(bundle, true);
+            }
+            catch (BundleException ex)
+            {
+                fireFrameworkEvent(FrameworkEvent.ERROR, bundle, ex);
+            }
         }
 
         // Remove the bundle from the installed map.