[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Kissme-general] More Classpath change problems
From: |
Eric Blake |
Subject: |
Re: [Kissme-general] More Classpath change problems |
Date: |
Thu, 28 Mar 2002 14:36:19 -0700 |
I cleaned your patch up a bit, and once I get it to compile, I'm
committing it. Thanks for the catch - I documented that the class
specified by java.system.class.loader must now have a constructor which
accepts a parent class loader.
John Leuner wrote:
>
> I tracked this down to the ClassLoader class.
>
>
> Otherwise getSystemClassLoader gets in an infinite loop where the Constructor
> for SystemClassLoader calls the ClassLoader() constructor which tries to use
> the system class loader as the parent classloader and round and round it goes
> ...
>
> John Leuner
>
2002-03-28 John Leuner <address@hidden>
* java/lang/ClassLoader.java (getSystemClassLoader): Break
infinite loop by specifying parent classloader.
* gnu/java/lang/SystemClassLoader.java (SystemClassLoader): Add
proper constructor.
--
This signature intentionally left boring.
Eric Blake address@hidden
BYU student, free software programmer
Index: gnu/java/lang/SystemClassLoader.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/java/lang/SystemClassLoader.java,v
retrieving revision 1.1
diff -u -r1.1 SystemClassLoader.java
--- gnu/java/lang/SystemClassLoader.java 22 Mar 2002 21:25:20 -0000
1.1
+++ gnu/java/lang/SystemClassLoader.java 28 Mar 2002 21:36:04 -0000
@@ -64,6 +64,17 @@
/** Flag to avoid infinite loops. */
private static boolean is_trying;
+
+ /**
+ * Creates a class loader. Note that the parent may be null, when this is
+ * created as the system class loader by ClassLoader.getSystemClassLoader.
+ *
+ * @param parent the parent class loader
+ */
+ public SystemClassLoader(ClassLoader parent)
+ {
+ super(parent);
+ }
/**
* Get the URL to a resource.
Index: java/lang/ClassLoader.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/lang/ClassLoader.java,v
retrieving revision 1.16
diff -u -r1.16 ClassLoader.java
--- java/lang/ClassLoader.java 22 Mar 2002 21:25:20 -0000 1.16
+++ java/lang/ClassLoader.java 28 Mar 2002 21:36:05 -0000
@@ -48,6 +48,7 @@
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
+import gnu.java.lang.SystemClassLoader;
import gnu.java.util.DoubleEnumeration;
import gnu.java.util.EmptyEnumeration;
@@ -685,7 +686,8 @@
* property <code>java.class.path</code>. This is set as the context
* class loader for a thread. The system property
* <code>java.system.class.loader</code>, if defined, is taken to be the
- * name of the class to use as the system class loader, otherwise this
+ * name of the class to use as the system class loader, which must have
+ * a public constructor which takes a ClassLoader as a parent; otherwise this
* uses gnu.java.lang.SystemClassLoader.
*
* <p>Note that this is different from the bootstrap classloader that
@@ -713,12 +715,28 @@
"gnu.java.lang.SystemClassLoader");
try
{
- return (ClassLoader) Class.forName(loader).newInstance();
+ // Give the new system class loader a null parent.
+ Constructor c = Class.forName(loader).getConstructor
+ ( new Class[] { ClassLoader.class } );
+ return (ClassLoader) c.newInstance(new Object[1]);
}
catch (Exception e)
{
- throw (Error) new InternalError
- ("System class loader could not be found: " + e).initCause(e);
+ try
+ {
+ System.err.println("Requested system classloader "
+ + loader + " failed, trying "
+ + "gnu.java.lang.SystemClassLoader");
+ e.printStackTrace();
+ // Fallback to gnu.java.lang.SystemClassLoader.
+ return new SystemClassLoader(null);
+ }
+ catch (Exception e1)
+ {
+ throw (Error) new InternalError
+ ("System class loader could not be found: " + e)
+ .initCause(e);
+ }
}
}
// Check if we may return the system classloader