Modified our hack to guess when boot delegation is necessary to check for
and ignore the Proxy class on the stack. Also now when checking to see if
the class loader of the class on the call stack is a bundle class loader,
it also walks up the class loader hierarchy just in case the class loader
is a custom class loader from a bundle.


git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@549493 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/framework/src/main/java/org/apache/felix/framework/searchpolicy/R4SearchPolicyCore.java b/framework/src/main/java/org/apache/felix/framework/searchpolicy/R4SearchPolicyCore.java
index 2e4feb1..93b9886 100755
--- a/framework/src/main/java/org/apache/felix/framework/searchpolicy/R4SearchPolicyCore.java
+++ b/framework/src/main/java/org/apache/felix/framework/searchpolicy/R4SearchPolicyCore.java
@@ -19,6 +19,7 @@
 package org.apache.felix.framework.searchpolicy;
 
 import java.io.IOException;
+import java.lang.reflect.Proxy;
 import java.net.URL;
 import java.security.ProtectionDomain;
 import java.util.*;
@@ -481,12 +482,23 @@
             }
             else if ((this.getClass().getClassLoader() != classes[i].getClassLoader())
                 && !ClassLoader.class.isAssignableFrom(classes[i])
-                && !Class.class.equals(classes[i]))
+                && !Class.class.equals(classes[i])
+                && !Proxy.class.equals(classes[i]))
             {
-                // If the instigating class was not from a bundle, then
-                // delegate to the parent class loader. Otherwise, break
-                // out of loop and return null.
-                if (!ContentClassLoader.class.isInstance(classes[i].getClassLoader()))
+                // If there are no bundles providing exports for this
+                // package and if the instigating class was not from a
+                // bundle, then delegate to the parent class loader.
+                // Otherwise, break out of loop and return null.
+                boolean delegate = true;
+                for (ClassLoader cl = classes[i].getClassLoader(); cl != null; cl = cl.getClass().getClassLoader())
+                {
+                    if (ContentClassLoader.class.isInstance(cl))
+                    {
+                        delegate = false;
+                        break;
+                    }
+                }
+                if (delegate)
                 {
                     return this.getClass().getClassLoader().loadClass(name);
                 }