You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (Jira)" <ji...@apache.org> on 2025/04/19 14:28:00 UTC
[jira] [Comment Edited] (GROOVY-9530) Groovy compiler inlines constants from precompiled classes when it's not safe to do so
[ https://issues.apache.org/jira/browse/GROOVY-9530?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17945865#comment-17945865 ]
Eric Milles edited comment on GROOVY-9530 at 4/19/25 2:27 PM:
--------------------------------------------------------------
This is the line in question: https://github.com/apache/groovy/blob/ed6ee9bc203f236f437af71bea34d8e6f22665b9/src/main/java/org/apache/groovy/ast/tools/ExpressionUtils.java#L282
The loaded class has its static field read at compile time.
If removed then items like this (Closure.DELEGATE_FIRST) fail to compile: https://github.com/apache/groovy/blob/ed6ee9bc203f236f437af71bea34d8e6f22665b9/src/main/groovy/groovy/util/FileTreeBuilder.groovy#L124
was (Author: emilles):
This is the line in question: https://github.com/apache/groovy/blob/ed6ee9bc203f236f437af71bea34d8e6f22665b9/src/main/java/org/apache/groovy/ast/tools/ExpressionUtils.java#L282
The loaded class has its static field read at compile time.
> Groovy compiler inlines constants from precompiled classes when it's not safe to do so
> --------------------------------------------------------------------------------------
>
> Key: GROOVY-9530
> URL: https://issues.apache.org/jira/browse/GROOVY-9530
> Project: Groovy
> Issue Type: Bug
> Components: Compiler
> Affects Versions: 3.0.3, 2.5.11
> Reporter: Marcin Erdmann
> Assignee: Eric Milles
> Priority: Major
>
> When a constant (a {{static final}} field) from a precompiled class (a class which is on compilation classpath) is referenced from a declaration of a {{static final}} field in a class which is being compiled the compiler will load and initialise the precompiled class during compilation and inline the value of the referenced constant even if it is not safe to do so, like for example if the value of the constant depends on the contents of the classpath at runtime.
> The issue does not happen in Groovy 2.4.19 but happens in 2.5.11 and 3.0.3
> The following project exposes the issue: https://github.com/erdi/groovy-constant-inlining-bug. If you run {{./gradlew :test}} which uses Groovy 2.4.19 it will pass but it will fail if you run {{./gradlew :testGroovy2_5}} or {{./gradlew testGroovy3_0}}.
> I believe the problem lies in {{org.apache.groovy.ast.tools.ExpressionUtils#transformInlineConstants(org.codehaus.groovy.ast.expr.Expression, org.codehaus.groovy.ast.ClassNode)}} when handling property expressions on non primary class nodes.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)