[FELIX-3803] Bundle#getResource and Bundle#findEntries always try to resolve the bundle (hence grabbing the bundle lock) even if the bundle is already resolved, which contradicts the spec

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1421961 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/framework/src/main/java/org/apache/felix/framework/BundleImpl.java b/framework/src/main/java/org/apache/felix/framework/BundleImpl.java
index 5d72142..79b709c 100644
--- a/framework/src/main/java/org/apache/felix/framework/BundleImpl.java
+++ b/framework/src/main/java/org/apache/felix/framework/BundleImpl.java
@@ -304,7 +304,7 @@
         }
 
         return getFramework().findBundleEntries(
-            adapt(BundleRevisionImpl.class), path, filePattern, recurse);
+                this, path, filePattern, recurse);
     }
 
     public Dictionary getHeaders()
@@ -1291,4 +1291,4 @@
     {
         return m_context;
     }
-}
\ No newline at end of file
+}
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 95c7b9c..78bbeed 100644
--- a/framework/src/main/java/org/apache/felix/framework/Felix.java
+++ b/framework/src/main/java/org/apache/felix/framework/Felix.java
@@ -1567,13 +1567,16 @@
         {
             return null;
         }
-        try
+        else if (bundle.getState() == Bundle.INSTALLED)
         {
-            resolveBundleRevision(bundle.adapt(BundleRevision.class));
-        }
-        catch (Exception ex)
-        {
-            // Ignore.
+            try
+            {
+                resolveBundleRevision(bundle.adapt(BundleRevision.class));
+            }
+            catch (Exception ex)
+            {
+                // Ignore.
+            }
         }
 
         // If the bundle revision isn't resolved, then just search
@@ -1603,13 +1606,16 @@
         {
             return null;
         }
-        try
+        else if (bundle.getState() == Bundle.INSTALLED)
         {
-            resolveBundleRevision(bundle.adapt(BundleRevision.class));
-        }
-        catch (Exception ex)
-        {
-            // Ignore.
+            try
+            {
+                resolveBundleRevision(bundle.adapt(BundleRevision.class));
+            }
+            catch (Exception ex)
+            {
+                // Ignore.
+            }
         }
 
         if (bundle.adapt(BundleRevision.class).getWiring() == null)
@@ -1688,13 +1694,33 @@
      * Implementation for Bundle.findEntries().
     **/
     Enumeration findBundleEntries(
+            BundleImpl bundle, String path, String filePattern, boolean recurse)
+    {
+        if (bundle.getState() == Bundle.UNINSTALLED)
+        {
+            throw new IllegalStateException("The bundle is uninstalled.");
+        }
+        else if (!Util.isFragment(bundle.adapt(BundleRevision.class)) && bundle.getState() == Bundle.INSTALLED)
+        {
+            try
+            {
+                resolveBundleRevision(bundle.adapt(BundleRevision.class));
+            }
+            catch (Exception ex)
+            {
+                // Ignore.
+            }
+        }
+        return findBundleEntries(
+                bundle.adapt(BundleRevision.class), path, filePattern, recurse);
+    }
+
+    /**
+     * Implementation for BundleWiring.findEntries().
+     **/
+    Enumeration findBundleEntries(
         BundleRevision revision, String path, String filePattern, boolean recurse)
     {
-        // Try to resolve the bundle per the spec.
-        List<Bundle> list = new ArrayList<Bundle>(1);
-        list.add(revision.getBundle());
-        resolveBundles(list);
-
         // Get the entry enumeration from the revision content and
         // create a wrapper enumeration to filter it.
         Enumeration enumeration =