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

Getting java.lang.NoSuchFieldError with groovy version 2.5.6

    XMLWordPrintableJSON

Details

    • Important

    Description

      Recently, I upgrade my spring boot application with version 2.1.3. I found many test cases started failing with error (Caused by: java.lang.NoSuchFieldError: it). After drilling down dependency list I noticed that groovy version 2.5.6 is being used. Which might be cauing these issues. Earlier it was groovy version 2.5.5 and my application was working just fine. I tried using version 2.5.5 explicitely in pom.xml and application again started working.

      This looks like a possible bug with version 2.5.6. After compaing .class file generated for both version found some difference which might be causing this issue:

      2.5.6 generated .class code: Here "TestGroovyNewVersion.AddressInd.it.addressInd" looks incorrect as 'it' not defined as var for AddressInd enum. Here 'it' isn't getting treated as an explicit parameter for closures.

      return ScriptBytecodeAdapter.compareEqual(TestGroovyNewVersion.AddressInd.it.addressInd, addressInd.get());

       

      2.5.5 generated .class code:

      return ScriptBytecodeAdapter.compareEqual(((TestGroovyNewVersion.AddressInd)it).addressInd,addressInd.get());

      Here is my groovy code and below line of code is given error:

      AddressInd indicator = values().find{ it.addressInd == addressInd }

       

      import com.fasterxml.jackson.annotation.JsonCreator
      import groovy.transform.CompileStatic
      import groovy.transform.ToString
      
      @ToString
      @CompileStatic
      class TestGroovyNewVersion {
       private enum AddressInd {
      
       REGISITERED_ADD('Registered add'), TRADING_ADD('Trading add'), DELIVERY_ADD('Delivery add'), INVOICE_ADD('Invoice add')
      
       protected String addressInd
      
       private AddressInd(final String addressInd) {
       this.addressInd = addressInd
       }
      
       @JsonCreator
       static AddressInd create(final String addressInd) {
         AddressInd indicator = values().find{ it.addressInd == addressInd }
         if (!indicator)
         {
           throw new IllegalArgumentException()
         }
         indicator
       }
       }
       String ref
       String companyNo
       String name
      }

       

      I would prefer to not make code changes in my code as I have similar at too many places at same time I don't want to use older version of groovy lib. Pls look into matter and suggest a solution or fix this issue if it is a possible bug in groovy 2.5.6.

       

      Attachments

        Activity

          People

            paulk Paul King
            itspanjain Pankaj
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: