Modified the R4 search policy to search the bundle's class path for
resources if the bundle cannot be resolved as described by the spec;
if the bundle is resolved then imported packages are also searched.
git-svn-id: https://svn.apache.org/repos/asf/incubator/felix/trunk@375024 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 e6d0d83..f754b75 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
@@ -275,13 +275,13 @@
// these packages cannot be provided by other bundles.
if (pkgName.startsWith("java."))
{
- return this.getClass().getClassLoader().loadClass(name);
+ return getClass().getClassLoader().loadClass(name);
}
// Look in the module's imports.
Class clazz = findImportedClass(module, name, pkgName);
- // If not found, try the module's own content.
+ // If not found, try the module's own class path.
if (clazz == null)
{
clazz = module.getContentLoader().getClass(name);
@@ -404,9 +404,16 @@
}
catch (ResolveException ex)
{
- // We do not use the resolve exception as the
- // cause of the exception, since this would
- // potentially leak internal module information.
+ // The spec states that if the bundle cannot be resolved, then
+ // only the local bundle's resources should be searched. So we
+ // will ask the module's own class path.
+ URL url = module.getContentLoader().getResource(name);
+ if (url != null)
+ {
+ return url;
+ }
+
+ // We need to throw a resource not found exception.
throw new ResourceNotFoundException(
name + ": cannot resolve package "
+ ex.getPackage());
@@ -419,13 +426,13 @@
// these packages cannot be provided by other bundles.
if (pkgName.startsWith("java."))
{
- return this.getClass().getClassLoader().getResource(name);
+ return getClass().getClassLoader().getResource(name);
}
// Look in the module's imports.
URL url = findImportedResource(module, name);
- // If not found, try the module's own content.
+ // If not found, try the module's own class path.
if (url == null)
{
url = module.getContentLoader().getResource(name);