classpath
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: A few small fixes


From: David Holmes
Subject: RE: A few small fixes
Date: Tue, 10 Jun 2003 08:24:17 +1000

> Jeroen Frijters wrote:
> Calling ClassLoader.loadClass(String, boolean) from Class.forName is
> incorrect and, more importantly, incompatible with Sun's
> implementation, ...

Why is it incorrect to call loadClass(name, true)?

Class.forName(String name, boolean init, ClassLoader cl) is required
to "locate, load and link [the given class] using the given
ClassLoader" and to initialize or not, depending on the init
parameter.

ClassLoader.loadClass(String name, boolean resolve) is required to
find and load the given class, and if found to resolve it, or not,
depending on the resolve parameter.

Remembering that resolve means link, this means that the first part of
Class.forName's job can be done by invoking: cl.loadClass(name, true);


As for "compatibility" with Sun's implementation I am at a loss.
First, I thought you classpath folk were supposed to remain untainted
from internal knowledge of the Sun implementation. ;-) Second, in
1.4.1 Class.forName delegates to a native method, while loadClass
implements the algorithm defined by its specification. So where is
there any kind of compatability issue?

The only potential problem with invoking a non-final method like
loadClass is that you are relying on it being overriden correctly, so
would have to be careful how you treated the returned class instance.
But if that is a concern then forName should just use a native method
or a VMxxx method - and neither the current code, nor the suggested
patch seems to have this concern.

David Holmes





reply via email to

[Prev in Thread] Current Thread [Next in Thread]