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: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED]] On 
> Behalf Of Eric Blake
> Sent: Wednesday, January 08, 2003 02:10
> To: Jeroen Frijters
> Cc: [EMAIL PROTECTED]
> 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             [EMAIL PROTECTED]
>    BYU student, free software programmer
> 
> 
> 
> 
> _______________________________________________
> Classpath mailing list
> [EMAIL PROTECTED]
> http://mail.gnu.org/mailman/listinfo/classpath
> 



_______________________________________________
Classpath mailing list
[EMAIL PROTECTED]
http://mail.gnu.org/mailman/listinfo/classpath

Reply via email to