FELIX-4867 Additional change to improve synchronization as suggested by Richard Hall


git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1676534 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 f3f7fbb..9d6eb88 100644
--- a/framework/src/main/java/org/apache/felix/framework/Felix.java
+++ b/framework/src/main/java/org/apache/felix/framework/Felix.java
@@ -2674,28 +2674,6 @@
 
     void uninstallBundle(BundleImpl bundle) throws BundleException
     {
-        // Populate a set of refresh candidates. This also includes any bundles that this bundle
-        // is wired to but have previously been uninstalled.
-        List<Bundle> refreshCandidates = new ArrayList<Bundle>();
-        refreshCandidates.add(bundle); // Add this bundle first, so that it gets refreshed first later on
-        BundleRevisions bundleRevisions = bundle.adapt(BundleRevisions.class);
-        if (bundleRevisions != null)
-        {
-            for (BundleRevision br : bundleRevisions.getRevisions())
-            {
-                BundleWiring bw = br.getWiring();
-                if (bw != null)
-                {
-                    for (BundleWire wire : bw.getRequiredWires(null))
-                    {
-                        Bundle b = wire.getProvider().getBundle();
-                        if (Bundle.UNINSTALLED == b.getState() && !refreshCandidates.contains(b))
-                            refreshCandidates.add(b);
-                    }
-                }
-            }
-        }
-
         // Acquire bundle lock.
         try
         {
@@ -2799,6 +2777,28 @@
         boolean locked = acquireGlobalLock();
         if (locked)
         {
+            // Populate a set of refresh candidates. This also includes any bundles that this bundle
+            // is wired to but have previously been uninstalled.
+            List<Bundle> refreshCandidates = new ArrayList<Bundle>();
+            refreshCandidates.add(bundle); // Add this bundle first, so that it gets refreshed first
+            BundleRevisions bundleRevisions = bundle.adapt(BundleRevisions.class);
+            if (bundleRevisions != null)
+            {
+                for (BundleRevision br : bundleRevisions.getRevisions())
+                {
+                    BundleWiring bw = br.getWiring();
+                    if (bw != null)
+                    {
+                        for (BundleWire wire : bw.getRequiredWires(null))
+                        {
+                            Bundle b = wire.getProvider().getBundle();
+                            if (Bundle.UNINSTALLED == b.getState() && !refreshCandidates.contains(b))
+                                refreshCandidates.add(b);
+                        }
+                    }
+                }
+            }
+
             try
             {
                 for (Bundle b : refreshCandidates)