Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Watson2013-02-20 22:24:34 +0000
committerThomas Watson2013-02-20 22:24:34 +0000
commit0d5c40d55fff4174d33ec45c039837dcafa934a1 (patch)
treecad4fbf045238b6304952439987c49f037d707b4 /bundles/org.eclipse.osgi/core
parent2bf140c910f5fd4651fcfc798610b7da950d1e51 (diff)
downloadrt.equinox.framework-0d5c40d55fff4174d33ec45c039837dcafa934a1.tar.gz
rt.equinox.framework-0d5c40d55fff4174d33ec45c039837dcafa934a1.tar.xz
rt.equinox.framework-0d5c40d55fff4174d33ec45c039837dcafa934a1.zip
Bug 375783 - DefaultClassLoader.getResources() ALWAYS delegates to parent Classloader
Diffstat (limited to 'bundles/org.eclipse.osgi/core')
-rw-r--r--bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/BundleHost.java2
-rw-r--r--bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/internal/loader/BundleLoader.java79
2 files changed, 40 insertions, 41 deletions
diff --git a/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/BundleHost.java b/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/BundleHost.java
index cfc55b0a3..312e1d069 100644
--- a/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/BundleHost.java
+++ b/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/BundleHost.java
@@ -287,7 +287,7 @@ public class BundleHost extends AbstractBundle {
if (loader == null)
result = bundledata.findLocalResources(name);
else
- result = loader.getResources(name);
+ result = loader.findResources(name);
if (result != null && result.hasMoreElements())
return result;
return null;
diff --git a/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/internal/loader/BundleLoader.java b/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/internal/loader/BundleLoader.java
index efa394bb3..718ce7f89 100644
--- a/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/internal/loader/BundleLoader.java
+++ b/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/internal/loader/BundleLoader.java
@@ -574,10 +574,6 @@ public class BundleLoader implements ClassLoaderDelegate {
* Finds the resource for a bundle. This method is used for delegation by the bundle's classloader.
*/
public URL findResource(String name) {
- return findResource(name, true);
- }
-
- URL findResource(String name, boolean checkParent) {
if ((name.length() > 1) && (name.charAt(0) == '/')) /* if name has a leading slash */
name = name.substring(1); /* remove leading slash before search */
String pkgName = getResourcePackageName(name);
@@ -585,7 +581,7 @@ public class BundleLoader implements ClassLoaderDelegate {
ClassLoader parentCL = getParentClassLoader();
// follow the OSGi delegation model
// First check the parent classloader for system resources, if it is a java resource.
- if (checkParent && parentCL != null) {
+ if (parentCL != null) {
if (pkgName.startsWith(JAVA_PACKAGE))
// 1) if startsWith "java." delegate to parent and terminate search
// we never delegate java resource requests past the parent
@@ -645,9 +641,9 @@ public class BundleLoader implements ClassLoaderDelegate {
result = policy.doBuddyResourceLoading(name);
if (result != null)
return result;
- // hack to support backwards compatibiility for bootdelegation
+ // hack to support backwards compatibility for bootdelegation
// or last resort; do class context trick to work around VM bugs
- if (parentCL != null && !bootDelegation && ((checkParent && bundle.getFramework().compatibiltyBootDelegation) || isRequestFromVM()))
+ if (parentCL != null && !bootDelegation && (bundle.getFramework().compatibiltyBootDelegation || isRequestFromVM()))
// we don't need to continue if the resource is not found here
return parentCL.getResource(name);
return result;
@@ -661,41 +657,58 @@ public class BundleLoader implements ClassLoaderDelegate {
if ((name.length() > 1) && (name.charAt(0) == '/')) /* if name has a leading slash */
name = name.substring(1); /* remove leading slash before search */
String pkgName = getResourcePackageName(name);
- Enumeration<URL> result = null;
+ Enumeration<URL> result = Collections.enumeration(Collections.<URL> emptyList());
+ boolean bootDelegation = false;
+ ClassLoader parentCL = getParentClassLoader();
+ // follow the OSGi delegation model
+ // First check the parent classloader for system resources, if it is a java resource.
+ if (parentCL != null) {
+ if (pkgName.startsWith(JAVA_PACKAGE))
+ // 1) if startsWith "java." delegate to parent and terminate search
+ // we never delegate java resource requests past the parent
+ return parentCL.getResources(name);
+ else if (bundle.getFramework().isBootDelegationPackage(pkgName)) {
+ // 2) if part of the bootdelegation list then delegate to parent and continue
+ result = compoundEnumerations(result, parentCL.getResources(name));
+ bootDelegation = true;
+ }
+ }
try {
- result = searchHooks(name, PRE_RESOURCES);
+ Enumeration<URL> hookResources = searchHooks(name, PRE_RESOURCES);
+ if (hookResources != null) {
+ return compoundEnumerations(result, hookResources);
+ }
} catch (ClassNotFoundException e) {
// will not happen
} catch (FileNotFoundException e) {
- return null;
- }
- if (result != null)
return result;
- // start at step 3 because of the comment above about ClassLoader#getResources
+ }
+
// 3) search the imported packages
PackageSource source = findImportedSource(pkgName, null);
if (source != null)
// 3) found import source terminate search at the source
- return source.getResources(name);
+ return compoundEnumerations(result, source.getResources(name));
// 4) search the required bundles
source = findRequiredSource(pkgName, null);
if (source != null)
// 4) attempt to load from source but continue on failure
- result = source.getResources(name);
+ result = compoundEnumerations(result, source.getResources(name));
// 5) search the local bundle
// compound the required source results with the local ones
Enumeration<URL> localResults = findLocalResources(name);
result = compoundEnumerations(result, localResults);
// 6) attempt to find a dynamic import source; only do this if a required source was not found
- if (result == null && source == null) {
+ if (source == null && !result.hasMoreElements()) {
source = findDynamicSource(pkgName);
if (source != null)
- return source.getResources(name);
+ return compoundEnumerations(result, source.getResources(name));
}
- if (result == null)
+ if (!result.hasMoreElements())
try {
- result = searchHooks(name, POST_RESOURCES);
+ Enumeration<URL> hookResources = searchHooks(name, POST_RESOURCES);
+ result = compoundEnumerations(result, hookResources);
} catch (ClassNotFoundException e) {
// will not happen
} catch (FileNotFoundException e) {
@@ -705,6 +718,13 @@ public class BundleLoader implements ClassLoaderDelegate {
Enumeration<URL> buddyResult = policy.doBuddyResourcesLoading(name);
result = compoundEnumerations(result, buddyResult);
}
+ // hack to support backwards compatibility for bootdelegation
+ // or last resort; do class context trick to work around VM bugs
+ if (!result.hasMoreElements()) {
+ if (parentCL != null && !bootDelegation && (bundle.getFramework().compatibiltyBootDelegation || isRequestFromVM()))
+ // we don't need to continue if the resource is not found here
+ return parentCL.getResources(name);
+ }
return result;
}
@@ -774,27 +794,6 @@ public class BundleLoader implements ClassLoaderDelegate {
return result;
}
- /*
- * This method is used by Bundle.getResources to do proper parent delegation.
- */
- public Enumeration<URL> getResources(String name) throws IOException {
- if ((name.length() > 1) && (name.charAt(0) == '/')) /* if name has a leading slash */
- name = name.substring(1); /* remove leading slash before search */
- String pkgName = getResourcePackageName(name);
- // follow the OSGi delegation model
- // First check the parent classloader for system resources, if it is a java resource.
- Enumeration<URL> result = null;
- if (pkgName.startsWith(JAVA_PACKAGE) || bundle.getFramework().isBootDelegationPackage(pkgName)) {
- // 1) if startsWith "java." delegate to parent and terminate search
- // 2) if part of the bootdelegation list then delegate to parent and continue of failure
- ClassLoader parentCL = getParentClassLoader();
- result = parentCL == null ? null : parentCL.getResources(name);
- if (pkgName.startsWith(JAVA_PACKAGE))
- return result;
- }
- return compoundEnumerations(result, findResources(name));
- }
-
public static <E> Enumeration<E> compoundEnumerations(Enumeration<E> list1, Enumeration<E> list2) {
if (list2 == null || !list2.hasMoreElements())
return list1;

Back to the top