Versions Compared

Key

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

Wiki Markup
According to the Java Language Specification \[[JLS 052005|AA. Java References#JLS 05]\], section 8.3.2.1 "Initializers for Class Variables":

...

Wiki Markup
According to the Java Language Specification \[[JLS 052005|AA. Java References#JLS 05]\], section 12.4 "Initialization of Classes and Interfaces":

...

Wiki Markup
This statement asserts that the presence of a {{static}} field triggers the initialization of a class, however, in this example, a recursive attempt is being made to initialize the class already. Because such recursive attempts are ignored by the JVM, the default value of {{deposit}} is {{0}} during the initialization. \[[Bloch 052005|AA. Java References#Bloch 05]\]

...

Wiki Markup
This noncompliant code example uses an inner class that extends the outer class. The outer class in turn, uses the {{static}} instance of the inner class. This results in a circular initialization issue \[[Findbugs 082008|AA. Java References#Findbugs 08]\].

...

Wiki Markup
Notably, class initialization cycles can also occur because of circularity in the code present within the {{static}} initializers of two or more classes \[[Findbugs 082008|AA. Java References#Findbugs 08]\]. Also see the related guideline [MSC08-J. Avoid cyclic dependencies between packages].

...

References

Wiki Markup
\[[JLS 052005|AA. Java References#JLS 05]\] Sections [8.3.2.1, Initializers for Class Variables|http://java.sun.com/docs/books/jls/third_edition/html/classes.html#8.3.2.1]; [12.4, Initialization of Classes and Interfaces|http://java.sun.com/docs/books/jls/third_edition/html/execution.html#12.4]
  Puzzle 49: Larger Than Life
\[[MITRE 092009|AA. Java References#MITRE 09]\] [CWE ID 665|http://cwe.mitre.org/data/definitions/665.html] "Improper Initialization"

...