Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Wiki Markup
            According to the _Java Language Specification_ (JLS), [§12.4, "Initialization of Classes and Interfaces" |http://java.sun.com/docs/books/jls/third_edition/html/execution.html#12.4] \[[JLS 2005|AA. Bibliography#JLSReferences#JLS 05]\]:

Initialization of a class consists of executing its static initializers and the initializers for static fields (class variables) declared in the class.

Wiki Markup
In other words, the presence of a {{static}} field triggers the initialization of a class. However, a static field could depend on the initialization of another class, possibly creating an initialization cycle. The JLS also states in [§8.3.2.1, "Initializers for Class Variables" |http://java.sun.com/docs/books/jls/third_edition/html/classes.html#8.3.2.1] \[[JLS 2005|AA. Bibliography#JLSReferences#JLS 05]\]

At run time, static variables that are final and that are initialized with compile-time constant values are initialized first.

...

Wiki Markup
The JLS permits implementations to ignore the possibility of such recursive initialization cycles \[[Bloch 2005|AA. Bibliography#BlochReferences#Bloch 05]\].  

Compliant Solution (Intra-class Cycle)

...

The CERT C++ Secure Coding Standard

DCL14-CPP. Avoid assumptions about the initialization order between translation units

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="edc9915e0b9b3e30-d023dc52-4eb64cc8-a8e48312-28d6d43bd6e08597c04f7f4b"><ac:plain-text-body><![CDATA[

[ISO/IEC TR 24772:2010

http://www.aitcnet.org/isai/]

Initialization of variables [LAV]

]]></ac:plain-text-body></ac:structured-macro>

...

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="55b1d89e11135d33-f126fb0d-469d4a45-b29c8dc9-68f92d23adbd5085d46babcc"><ac:plain-text-body><![CDATA[

[[JLS 2005

AA. Bibliography#JLS References#JLS 05]]

[§8.3.2.1, Initializers for Class Variables

http://java.sun.com/docs/books/jls/third_edition/html/classes.html#8.3.2.1]

]]></ac:plain-text-body></ac:structured-macro>

 

§12.4, Initialization of Classes and Interfaces

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="4e501483609a679f-1795690c-46aa4498-a6d8a492-41bc5fa84f813e16f749cca5"><ac:plain-text-body><![CDATA[

[[Bloch 2005

AA. Bibliography#Bloch References#Bloch 05]]

Puzzle 49. Larger than life

]]></ac:plain-text-body></ac:structured-macro>

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="2bcc331a3a2c8833-8bdbd8d9-4a534d57-bc669764-beb230023f2c61d518893715"><ac:plain-text-body><![CDATA[

[[MITRE 2009

AA. Bibliography#MITRE References#MITRE 09]]

[CWE-665

http://cwe.mitre.org/data/definitions/665.html]. Improper initialization

]]></ac:plain-text-body></ac:structured-macro>

...