tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Konstantin Preißer <>
Subject RE: [OT] Querstion about Class.forName() re. ClassLoaders
Date Fri, 10 May 2013 23:04:03 GMT
Hi Konstantin,

> -----Original Message-----
> From: Konstantin Kolinko []
> Sent: Friday, May 10, 2013 11:46 PM
> Yes, the same.
> BTW, Oracle JDKs come with source code for their public classes, On
> Windows that is %JAVA_HOME%/ Do you have such file?

Thank you for your answer. Yes, I have that file and I looked there, but that Class.forName(String)
method calls a native method for which I couldn't find the source.

I asked this question because the above is not what is implemented by Sun/Oracles JRE (I tested
with Windows 32-bit versions of JRE 1.7.0_21, Java 8 EA (b88) and Java 5).

It seems that in Oracles Java, Class.forName(String) uses the ClassLoader of the class which
implements the method that makes the call to Class.forName(), not the ClassLoader of the class
on whose instance the method is called (which is the one used when calling getClass().getClassLoader()).
This can make a difference e.g. if the Class with that method has a subclass and you call
the method on an instance of the subclass (which is what I experienced with a Eclipse RCP
app which uses a ClassLoader hierarchy for plugins).

However, since the bug exists in current Java 1.7.0_21 (from 2013) and even in Java 1.5.0
(2004), I wondered if nobody else noticed this discrepancy between the JavaDoc and the actual
implementation or maybe if Sun/Oracle just doesn't fix such bugs. (I already submitted a bug
report on December 1, 2012, but did not yet receive a response - so I wanted to make sure
my understanding was correct).


Konstantin Preißer 

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message