Found another issue in boot delegation when it comes to classes/resources
in the default package (i.e., no package name). For now, no delegation to
the parent class loader will occur if there is no package name.
Also, modified the diagnostics to use the same class loader for checking
the parent class loader as the one that is actually used for boot delegation.
git-svn-id: https://svn.apache.org/repos/asf/incubator/felix/trunk@395282 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 b32db8f..c32751e 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
@@ -304,12 +304,18 @@
// 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())))
- || (!m_bootPkgWildcards[i] && m_bootPkgs[i].equals(pkgName)))
+ if (pkgName.length() > 0)
{
- return getClass().getClassLoader().loadClass(name);
+ // Only consider delegation if we have a package name, since
+ // we don't want to promote the default package. The spec does
+ // not take a stand on this issue.
+ if ((m_bootPkgWildcards[i] &&
+ (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);
+ }
}
}
@@ -468,12 +474,18 @@
// 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())))
- || (!m_bootPkgWildcards[i] && m_bootPkgs[i].equals(pkgName)))
+ if (pkgName.length() > 0)
{
- return getClass().getClassLoader().getResource(name);
+ // Only consider delegation if we have a package name, since
+ // we don't want to promote the default package. The spec does
+ // not take a stand on this issue.
+ if ((m_bootPkgWildcards[i] &&
+ (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);
+ }
}
}
@@ -1859,7 +1871,7 @@
boolean classpath = false;
try
{
- ClassLoader.getSystemClassLoader().loadClass(name);
+ getClass().getClassLoader().loadClass(name);
classpath = true;
}
catch (Exception ex)
@@ -1881,7 +1893,7 @@
sb.append(" does export it.");
if (classpath)
{
- sb.append(" There are two fixes: 1) Add an import for '");
+ sb.append(" Additionally, the class is also available from the system class loader. There are two fixes: 1) Add an import for '");
sb.append(pkgName);
sb.append("' to bundle ");
sb.append(impId);
@@ -1912,7 +1924,7 @@
{
try
{
- ClassLoader.getSystemClassLoader().loadClass(name);
+ getClass().getClassLoader().loadClass(name);
exported = true;