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

Constant integer and double expressions in AstBuilder.buildFromCode { } cause NoSuchFieldErrors at runtime

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 1.7.3
    • Fix Version/s: 1.7.4, 1.8-beta-1
    • Component/s: ast builder
    • Labels:
      None

      Description

      the following blocks of code cause a NoSuchFieldError at runtime in the transformed class due to failure to look up a constant:

      new AstBuilder.buildFromCode

      { return 1 }

      new AstBuilder.buildFromCode

      { return 1.0 }

      new AstBuilder.buildFromString("return 1")

      I've attached an example and the test that shows the failure.

      The current workaround is to use the String constructor of their java.lang.Number equivalents:

      new AstBuilder.buildFromCode

      { return new Integer("1") }

      new AstBuilder.buildFromCode

      { return new Double("1.0") }

      My suspicion is that the compiler is optimizing the inline constants away, but that the reference to those constants are in some intermediary generated class which is thrown away later instead of the intended target classes.

        Attachments

        1. 4272_v17x.patch
          1 kB
          Roshan Dawrani
        2. MyConstantsTest.groovy
          0.3 kB
          Brian M. Carr
        3. MyConstantsASTTransformation.groovy
          2 kB
          Brian M. Carr
        4. MyConstants.java
          0.4 kB
          Brian M. Carr

          Activity

            People

            • Assignee:
              roshandawrani Roshan Dawrani
              Reporter:
              bcarr Brian M. Carr
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: