Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-9530

Groovy compiler inlines constants from precompiled classes when it's not safe to do so

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 3.0.3, 2.5.11
    • None
    • Compiler
    • None

    Description

      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.

      Attachments

        Activity

          People

            Unassigned Unassigned
            erdi Marcin Erdmann
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: