Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPascal Rapicault2006-07-11 09:59:44 -0400
committerPascal Rapicault2006-07-11 09:59:44 -0400
commit948ed11a50c7436d428546c3d8e7c7844c98b2c9 (patch)
tree389bc849e24895695a68d476e3f9a9d02904c680
parentcd9c15605821996a31f1ec9f32959286d2f1a6fb (diff)
downloadrt.equinox.framework-948ed11a50c7436d428546c3d8e7c7844c98b2c9.tar.gz
rt.equinox.framework-948ed11a50c7436d428546c3d8e7c7844c98b2c9.tar.xz
rt.equinox.framework-948ed11a50c7436d428546c3d8e7c7844c98b2c9.zip
Bug 149754 - ContextFinder can enter in infinite loop while delegating to other classloaders
-rw-r--r--bundles/org.eclipse.osgi/eclipseAdaptor/src/org/eclipse/core/runtime/internal/adaptor/ContextFinder.java86
1 files changed, 63 insertions, 23 deletions
diff --git a/bundles/org.eclipse.osgi/eclipseAdaptor/src/org/eclipse/core/runtime/internal/adaptor/ContextFinder.java b/bundles/org.eclipse.osgi/eclipseAdaptor/src/org/eclipse/core/runtime/internal/adaptor/ContextFinder.java
index 76d1dad24..e6d220bb9 100644
--- a/bundles/org.eclipse.osgi/eclipseAdaptor/src/org/eclipse/core/runtime/internal/adaptor/ContextFinder.java
+++ b/bundles/org.eclipse.osgi/eclipseAdaptor/src/org/eclipse/core/runtime/internal/adaptor/ContextFinder.java
@@ -35,6 +35,7 @@ public class ContextFinder extends ClassLoader implements PrivilegedAction {
}
});
}
+ private static ThreadLocal cycleDetector = new ThreadLocal();
public ContextFinder(ClassLoader contextClassLoader) {
super(contextClassLoader);
@@ -82,41 +83,80 @@ public class ContextFinder extends ClassLoader implements PrivilegedAction {
return basicFindClassLoaders();
}
+ private boolean startLoading(String name) {
+ Set classesAndResources = (Set) cycleDetector.get();
+ if (classesAndResources != null && classesAndResources.contains(name))
+ return false;
+
+ if (classesAndResources == null) {
+ classesAndResources = new HashSet(3);
+ cycleDetector.set(classesAndResources);
+ }
+ classesAndResources.add(name);
+ return true;
+ }
+
+ private void stopLoading(String name) {
+ ((Set) cycleDetector.get()).remove(name);
+ }
+
protected synchronized Class loadClass(String arg0, boolean arg1) throws ClassNotFoundException {
+ //Shortcut cycle
+ if (startLoading(arg0) == false)
+ throw new ClassNotFoundException(arg0);
+
try {
- return super.loadClass(arg0, arg1);
- } catch (ClassNotFoundException e) {
- // Ignore; find a bundle classloader to use.
- }
- ArrayList toConsult = findClassLoaders();
- for (Iterator loaders = toConsult.iterator(); loaders.hasNext();)
try {
- return ((ClassLoader) loaders.next()).loadClass(arg0);
+ return super.loadClass(arg0, arg1);
} catch (ClassNotFoundException e) {
- // go to the next class loader
+ // Ignore; find a bundle classloader to use.
}
- throw new ClassNotFoundException(arg0);
+ ArrayList toConsult = findClassLoaders();
+ for (Iterator loaders = toConsult.iterator(); loaders.hasNext();)
+ try {
+ return ((ClassLoader) loaders.next()).loadClass(arg0);
+ } catch (ClassNotFoundException e) {
+ // go to the next class loader
+ }
+ throw new ClassNotFoundException(arg0);
+ } finally {
+ stopLoading(arg0);
+ }
}
protected URL findResource(String arg0) {
- ArrayList toConsult = findClassLoaders();
- for (Iterator loaders = toConsult.iterator(); loaders.hasNext();) {
- URL result = ((ClassLoader) loaders.next()).getResource(arg0);
- if (result != null)
- return result;
- // go to the next class loader
+ //Shortcut cycle
+ if (startLoading(arg0) == false)
+ return null;
+ try {
+ ArrayList toConsult = findClassLoaders();
+ for (Iterator loaders = toConsult.iterator(); loaders.hasNext();) {
+ URL result = ((ClassLoader) loaders.next()).getResource(arg0);
+ if (result != null)
+ return result;
+ // go to the next class loader
+ }
+ return super.findResource(arg0);
+ } finally {
+ stopLoading(arg0);
}
- return super.findResource(arg0);
}
protected Enumeration findResources(String arg0) throws IOException {
- ArrayList toConsult = findClassLoaders();
- for (Iterator loaders = toConsult.iterator(); loaders.hasNext();) {
- Enumeration result = ((ClassLoader) loaders.next()).getResources(arg0);
- if (result != null && result.hasMoreElements())
- return result;
- // go to the next class loader
+ //Shortcut cycle
+ if (startLoading(arg0) == false)
+ return null;
+ try {
+ ArrayList toConsult = findClassLoaders();
+ for (Iterator loaders = toConsult.iterator(); loaders.hasNext();) {
+ Enumeration result = ((ClassLoader) loaders.next()).getResources(arg0);
+ if (result != null && result.hasMoreElements())
+ return result;
+ // go to the next class loader
+ }
+ return super.findResources(arg0);
+ } finally {
+ stopLoading(arg0);
}
- return super.findResources(arg0);
}
}

Back to the top