As a side effect to
GROOVY-5150, the class constant pool is used for non final fields too:
I have this class:
compile it with javac and you get the following related to i (using javap):
Compile it with groovyc and these days I seem to get this:
Now I thought the 'constant value' attribute for field objects was for proper constants (i.e. final fields), not for initialization values. That seems to be what it indicates here:
4.7.2 The ConstantValue Attribute
The ConstantValue attribute is a fixed-length attribute used in the attributes table of the field_info (§4.5) structures. A ConstantValue attribute represents the value of a constant field that must be (explicitly or implicitly) static;
Indeed javac will only use that attribute if I make the field final.
Now the JVM doesn't seem to be particularly strict here and the static does get the right value initially and allow it to be changed (at least on the VM version I'm using, haven't tried any others). It just seems to be a slight abuse of the meaning of constant value. I guess I just wanted to check it was deliberate.