JDK-7194006 : A new Class.forName(String cn, boolean initialize) method
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.lang:reflect
  • Affected Version: 8
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • OS: generic
  • CPU: generic
  • Submitted: 2012-08-24
  • Updated: 2016-04-08
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
tbd_majorUnresolved
Related Reports
Relates :  
Relates :  
Relates :  
Description
Class.forName(String cn) is a convenient method equivalent to:
   Class.forName(cn, true, currentLoader);

Class.forName(String) method will load a class and its <clinit> will
be invoked.

To load a class but to skip class initialization using the defining loader 
of the caller's class, it will have to call, e.g. if call from an instance method:
   Class.forName(cn, false, this.getClass().getClassLoader());

Additional comment from Remi Forax [1]:
> In fact, this method is really useful, most of the tools that does 
> bytecode transformation at runtime (most O/R mappers, 
> dynamic language runtimes, profilers, code coverage tools, etc)
> are now required to compute the stack frame attribute which requires to 
> compute the lower upper bound of a set of types. For that, being able
> to crawle the type hierachy without loading the static initializer
> is a must have.

[1] http://mail.openjdk.java.net/pipermail/jigsaw-dev/2012-May/002529.html

Comments
EVALUATION This may also be useful for JDK modularization as system classes will be loaded by non-null module loader in modular world. There may be more usage in the JDK of calling: Class.forName(classname, false, this.getClass().getClassLoader()) JDK code currently calls Class.forName(classname, false, null);
24-08-2012