United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6845426 non-static <clinit> method with no args is called during the class initialization process
JDK-6845426 : non-static method with no args is called during the class initialization process

Details
Type:
Bug
Submit Date:
2009-05-27
Status:
Closed
Updated Date:
2011-04-25
Project Name:
JDK
Resolved Date:
2011-04-25
Component:
hotspot
OS:
generic
Sub-Component:
runtime
CPU:
generic
Priority:
P2
Resolution:
Fixed
Affected Versions:
6,7
Fixed Versions:
hs21 (b05)

Related Reports
Backport:

Sub Tasks

Description
JVMS 2ed states the following regarding <clinit> methods:
  --- Excerpt-from-spec ---
  3.9 Specially Named Initialization Methods
  
  A class or interface has at most one class or interface initialization
  method and is initialized (2.17.4) by invoking that method. The
  initialization method of a class or interface is static and takes no
  arguments. It has the special name <clinit>. This name is supplied by
  a compiler. Because the name <clinit> is not a valid identifier, it
  cannot be used directly in a program written in the Java programming
  language. Class and interface initialization methods are invoked
  implicitly by the Java virtual machine; they are never invoked
  directly from any Java virtual machine instruction, but are invoked
  only indirectly as part of the class initialization process.
  --- End-Of-Excerpt ---

However, if a class contains non-static <clinit>()V method then the method
is still called by JVM as in case of "right" static <clinit>()V method.

                                    

Comments
EVALUATION

http://hg.openjdk.java.net/jdk7/hotspot-rt/hotspot/rev/dbad0519a1c4
                                     
2011-03-05
EVALUATION

Please note that for backward compatibility reasons, the new behavior of requiring an ACC_STATIC modifier for <clinit> methods will only occur for classfiles with classfile version >= 51.
                                     
2011-03-07



Hardware and Software, Engineered to Work Together