From 1b2c72aeed98aed042f3f87354a56a612c5f7981 Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Wed, 6 May 2009 20:19:15 +0000 Subject: Modified ObjectRunner to use Extension classloa... Modified ObjectRunner to use Extension classloader as parent rather than System classloader. Fixes bug #857. --- src/compiler/scala/tools/nsc/ObjectRunner.scala | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/compiler/scala/tools/nsc/ObjectRunner.scala b/src/compiler/scala/tools/nsc/ObjectRunner.scala index 7f97e06ca5..58da7b16eb 100644 --- a/src/compiler/scala/tools/nsc/ObjectRunner.scala +++ b/src/compiler/scala/tools/nsc/ObjectRunner.scala @@ -16,10 +16,27 @@ import java.net.{URL, URLClassLoader} * @author Lex Spoon * @version 1.1, 2007/7/13 */ -object ObjectRunner { +object ObjectRunner +{ + // we cannot use the app classloader here or we get what looks to + // be classloader deadlock, but if we pass null we bypass the extension + // classloader and our extensions, so we search the hierarchy to find + // the classloader whose parent is null. Resolves bug #857. + private def findExtClassLoader(): ClassLoader = { + def search(cl: ClassLoader): ClassLoader = { + if (cl == null) null + else if (cl.getParent == null) cl + else search(cl.getParent) + } + + search(Thread.currentThread.getContextClassLoader) + } + /** Create a class loader for the specified class path */ - private def makeClassLoader(classpath: List[URL]) = - new URLClassLoader(classpath.toArray, null) + private def makeClassLoader(classpath: List[URL]): URLClassLoader = + makeClassLoader(classpath, findExtClassLoader()) + private def makeClassLoader(classpath: List[URL], parent: ClassLoader): URLClassLoader = + new URLClassLoader(classpath.toArray, parent) /** Look up a class with a given class path. */ private def findClass(loader: ClassLoader, objectName: String) -- cgit v1.2.3