[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: Class.forName() bug
From: |
Jeroen Frijters |
Subject: |
RE: Class.forName() bug |
Date: |
Wed, 8 Jan 2003 09:17:09 +0100 |
ClassLoader.loadClass() should never initialize the class it loads. The
initialization should be in Class.forName, but that is missing is the
reference implementation as well.
Here is how my Class.forName() looks:
public static Class forName(String name, boolean initialize,
ClassLoader classloader)
throws ClassNotFoundException
{
if (classloader == null)
{
Class c = loadBootstrapClass(name, initialize);
if(c == null)
{
throw new ClassNotFoundException(name);
}
if(initialize)
{
initializeType(c.getType());
}
return c;
}
// if "name" is an array, we shouldn't pass it to the classloader
// (note that loadBootstrapClass
// can handle arrays, so the code above doesn't need this check)
if(name.startsWith("["))
{
return loadArrayClass(name, classloader);
}
Class c = classloader.loadClass(name, initialize);
if(initialize)
{
initializeType(c.getType());
}
return c;
}
private static native Class loadArrayClass(String name, Object classLoader);
static native Class loadBootstrapClass(String name, boolean initialize);
private static native void initializeType(Type type);
Regards,
Jeroen
http://ikvm.net -- Java VM for .NET
> -----Original Message-----
> From: address@hidden
> [mailto:address@hidden On
> Behalf Of Eric Blake
> Sent: Wednesday, January 08, 2003 02:10
> To: Jeroen Frijters
> Cc: address@hidden
> Subject: Re: Class.forName() bug
>
>
> Jeroen Frijters wrote:
> > Hi,
> >
> > When Class.forName() is called with an array classname
> (e.g. "[LFoo;"), it
> > calls classloader.loadClass() with the same string, but
> this isn't correct.
> > It should instead load "Foo" and then call a VM native method that
> > constructs the array class.
>
> Be careful, though. Class.forName("[LFoo;") is documented as NOT
> initializing Foo; does ClassLoader.loadClass() initialize Foo against
> our wishes?
>
> --
> This signature intentionally left boring.
>
> Eric Blake address@hidden
> BYU student, free software programmer
>
>
>
>
> _______________________________________________
> Classpath mailing list
> address@hidden
> http://mail.gnu.org/mailman/listinfo/classpath
>