class loader

Mark Wielaard mark@klomp.org
Tue Apr 3 14:56:00 GMT 2001


On Tue, Apr 03, 2001 at 11:44:51AM -0600, Tom Tromey wrote:
> >>>>> "Jeff" == Jeff Sturm <jsturm@one-point.com> writes:
>> >> The argument is: `null' is correct as far as the docs go, but some
> >> real programs rely on the return value never being null. Apparently
> >> neither the Sun nor IBM JDKs ever return null, so in effect we would
> >> be making this change in the name of bug compatibility.
>> Jeff> Not true. Try the following on any version of the JDK:
> Jeff> System.out.println(Class.forName("java.lang.Object").getClassLoader());
>> Thanks. I hadn't tried it -- I just took the reporter on faith.
> In that case I think we should just leave it as-is.

You don't have to change it. The following is from Inside Java 2 Platform
Security by Li Gong (3.12 Summary and Lessons Learned):
 We did encounter two artifacts in the JDK 1.0 which, although inconvenient
 were not changed. First, system classes have been traditionally loaded
 with a primordial class loader, [...]. As a result, all system classes
 (now called bootstrap classes in JDK 1.2) are loaded from within the Java
 runtime with a null system class loader. This particular implementation
 feature, however, became a sort of de facto API. Some programmers started
 to test for the existence of class loaders as a way to distinguish between
 system and nonsystem classes, [...]. For backward compatibility, JDK 1.2
 provides that system classes (or at least those classes necessary for
 bootstrapping the Java virtual machine) are loaded by the null class loader.
 This association between system classes and the null class loader coupled
 with the different treatment of classes based on their class loader types,
 however, makes it difficult to subdivide system classes into various
 packages or JAR files and then give them separate sets of permissions.
 [...] Hindsight tells us that it would have been much easier to evolve the
 design if all system classes were originally loaded with a special, but
 non-null, classloader.
So the original reporter is kind of right that it is strange that there are
classes that have a null class loader. But it is a bug/feature of the system
(for now).
Cheers,
Mark
-- 
Stuff to read:
 < http://www.toad.com/gnu/whatswrong.html >
 What's Wrong with Copy Protection, by John Gilmore


More information about the Java mailing list

AltStyle によって変換されたページ (->オリジナル) /