Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
3.0.14, 4.0.7
-
None
Description
If we define a constant that is resolved during runtime in a Groovy class and reference it in a Java class, it's value gets a static default value in the Java class. This seems to be a regression in Groovy 3.0.10 as earlier versions don't have the problem. Also affects all 4.0.x versions that I tested.
Example:
// G.groovy class G { public static final int DYNAMIC_CONSTANT = (9.9).intValue() }
// J.java public class J { public static void main(String[] args) { System.out.println(G.DYNAMIC_CONSTANT); } }
Groovy 4.0.7
Prints 0 with the following bytecode for J#main
0: getstatic #2 // Field java/lang/System.out:Ljava/io/PrintStream; 3: iconst_0 4: invokevirtual #4 // Method java/io/PrintStream.println:(I)V 7: return
Groovy 3.0.9
Correctly prints 9 with the following bytecode:
0: getstatic #2 // Field java/lang/System.out:Ljava/io/PrintStream; 3: getstatic #3 // Field G.DYNAMIC_CONSTANT:I 6: invokevirtual #4 // Method java/io/PrintStream.println:(I)V 9: return
Attachments
Issue Links
- is related to
-
GROOVY-10611 Static fields not initialized when accessed from another class
- Closed
- relates to
-
GROOVY-10928 Invalid stub code for interface field
- Closed
-
GROOVY-11019 joint compilation: public static final string does not compile
- Closed