Wiki Markup |
---|
According to the Java Language Specification \[[JLS 2005|AA. Bibliography#JLS 05]\], sectionSection 8.3.2.1, "Initializers for Class Variables": |
...at run time,
static
variables that arefinal
and that are initialized with compile-time constant values are initialized first.
...
Wiki Markup |
---|
According to the Java Language Specification \[[JLS 2005|AA. Bibliography#JLS 05]\], sectionSection 12.4, "Initialization of Classes and Interfaces": |
Initialization of a class consists of executing its
static
initializers and the initializers forstatic
fields (class variables) declared in the class.
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 2005|AA. Bibliography#Bloch 05]\]. |
Compliant Solution
This compliant solution changes the initialization order of the class Cycle
so that the fields meant to be used in computations get duly initialized.
...
Initialization cycles may lead to unexpected results.
Rule Guideline | Severity | Likelihood | Remediation Cost | Priority | Level |
---|---|---|---|---|---|
MSC07-J | low | unlikely | medium | P2 | L3 |
...