[
https://issues.apache.org/jira/browse/GROOVY-10902?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Eric Milles resolved GROOVY-10902.
----------------------------------
Resolution: Fixed
https://github.com/apache/groovy/commit/2926b8cbc293fd46b73b051fbaf5bde9eeeb7065
> Dynamic constants for primitive types get default value in Java
> ---------------------------------------------------------------
>
> Key: GROOVY-10902
> URL: https://issues.apache.org/jira/browse/GROOVY-10902
> Project: Groovy
> Issue Type: Bug
> Components: Stub generator / Joint compiler
> Affects Versions: 3.0.14, 4.0.7
> Reporter: Onni Koskinen
> Assignee: Eric Milles
> Priority: Major
>
> 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:
> {code:groovy}
> // G.groovy
> class G {
> public static final int DYNAMIC_CONSTANT = (9.9).intValue()
> } {code}
> {code:java}
> // J.java
> public class J {
> public static void main(String[] args) {
> System.out.println(G.DYNAMIC_CONSTANT);
> }
> } {code}
> *Groovy 4.0.7*
> Prints 0 with the following bytecode for J#main
> {code:java}
> 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{code}
> *Groovy 3.0.9*
> Correctly prints 9 with the following bytecode:
> {code:java}
> 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 {code}
>
>
--
This message was sent by Atlassian Jira
(v8.20.10#820010)