Fixed a boot delegation bug with resource loading that was previously fixed
for class loading, but not copied over for resource loading...we could
investigate merging these to avoid such errors.

Also improved the dianostic error message for class loading errors that
occur with exporters available.


git-svn-id: https://svn.apache.org/repos/asf/incubator/felix/trunk@395255 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/R4SearchPolicyCore.java b/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/R4SearchPolicyCore.java
index 0209373..b32db8f 100755
--- a/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/R4SearchPolicyCore.java
+++ b/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/R4SearchPolicyCore.java
@@ -301,12 +301,12 @@
             // A wildcarded boot delegation package will be in the form of "foo.",
             // so if the package is wildcarded do a startsWith() or a regionMatches()
             // to ignore the trailing "." to determine if the request should be
-            // delegated to the paren class loader. If the package is not wildcarded,
+            // delegated to the parent class loader. If the package is not wildcarded,
             // then simply do an equals() test to see if the request should be
             // delegated to the parent class loader.
             if ((m_bootPkgWildcards[i] &&
-                    (pkgName.startsWith(m_bootPkgs[i]) ||
-                    m_bootPkgs[i].regionMatches(0, pkgName, 0, pkgName.length())))
+                (pkgName.startsWith(m_bootPkgs[i]) ||
+                m_bootPkgs[i].regionMatches(0, pkgName, 0, pkgName.length())))
                 || (!m_bootPkgWildcards[i] && m_bootPkgs[i].equals(pkgName)))
             {
                 return getClass().getClassLoader().loadClass(name);
@@ -465,12 +465,12 @@
             // A wildcarded boot delegation package will be in the form of "foo.",
             // so if the package is wildcarded do a startsWith() or a regionMatches()
             // to ignore the trailing "." to determine if the request should be
-            // delegated to the paren class loader. If the package is not wildcarded,
+            // delegated to the parent class loader. If the package is not wildcarded,
             // then simply do an equals() test to see if the request should be
             // delegated to the parent class loader.
             if ((m_bootPkgWildcards[i] &&
-                    (pkgName.startsWith(m_bootPkgs[i]) ||
-                    m_bootPkgs[i].regionMatches(0, pkgName, 0, m_bootPkgs[i].length() - 1)))
+                (pkgName.startsWith(m_bootPkgs[i]) ||
+                m_bootPkgs[i].regionMatches(0, pkgName, 0, pkgName.length())))
                 || (!m_bootPkgWildcards[i] && m_bootPkgs[i].equals(pkgName)))
             {
                 return getClass().getClassLoader().getResource(name);
@@ -486,7 +486,7 @@
             if (url == null)
             {
                 url = module.getContentLoader().getResource(name);
-        
+
                 // If still not found, then try the module's dynamic imports.
                 if (url == null)
                 {
@@ -1856,6 +1856,16 @@
             if (exporters.length > 0)
             {
                 exported = true;
+                boolean classpath = false;
+                try
+                {
+                    ClassLoader.getSystemClassLoader().loadClass(name);
+                    classpath = true;
+                }
+                catch (Exception ex)
+                {
+                    // Ignore
+                }
    
                 long expId = Util.getBundleIdFromModuleId(exporters[0].getId());
    
@@ -1868,16 +1878,28 @@
                 sb.append(pkgName);
                 sb.append("' even though bundle ");
                 sb.append(expId);
-                sb.append(" does export it. There are two fixes: 1) Add an import for '");
-                sb.append(pkgName);
-                sb.append("' to bundle ");
-                sb.append(impId);
-                sb.append("; imports are necessary for each class directly touched by bundle code or indirectly touched, such as super classes if their methods are used. ");
-                sb.append("2) Add package '");
-                sb.append(pkgName);
-                sb.append("' to the '");
-                sb.append(Constants.FRAMEWORK_BOOTDELEGATION);
-                sb.append("' property; a library or VM bug can cause classes to be loaded by the wrong class loader. The first approach is preferable for preserving modularity.");
+                sb.append(" does export it.");
+                if (classpath)
+                {
+                    sb.append(" There are two fixes: 1) Add an import for '");
+                    sb.append(pkgName);
+                    sb.append("' to bundle ");
+                    sb.append(impId);
+                    sb.append("; imports are necessary for each class directly touched by bundle code or indirectly touched, such as super classes if their methods are used. ");
+                    sb.append("2) Add package '");
+                    sb.append(pkgName);
+                    sb.append("' to the '");
+                    sb.append(Constants.FRAMEWORK_BOOTDELEGATION);
+                    sb.append("' property; a library or VM bug can cause classes to be loaded by the wrong class loader. The first approach is preferable for preserving modularity.");
+                }
+                else
+                {
+                    sb.append(" To resolve this issue, add an import for '");
+                    sb.append(pkgName);
+                    sb.append("' to bundle ");
+                    sb.append(impId);
+                    sb.append(".");
+                }
                 sb.append("\n****\n****");
 
                 m_logger.log(Logger.LOG_ERROR, sb.toString());