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

Surprising Behavior With @CompileStatic And Collection.putAt

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Blocker
    • Resolution: Fixed
    • 2.1.1, 2.1.2, 2.1.3
    • 2.1.4
    • Compiler
    • None

    Description

      Helper.groovy
      @groovy.transform.CompileStatic
      class Helper {
          void addToCollection(Collection coll, int index, val) {
              coll[index] = val
          }
      }
      

      Compiled with 2.1.1 the decompiled class looks something like this:

      import groovy.lang.GroovyObject;
      import groovy.lang.MetaClass;
      import groovy.transform.TypeChecked.TypeCheckingInfo;
      import java.util.Collection;
      
      public class Helper
        implements GroovyObject
      {
        public Helper()
        {
          Helper this;
          MetaClass localMetaClass = $getStaticMetaClass();
          this.metaClass = localMetaClass;
        }
      
        @TypeChecked.TypeCheckingInfo(inferredType="AAlDbGFzc05vZGUAAAFWAP////8=", version=1)
        public void addToCollection(Collection coll, int index, Object val)
        {
          Object localObject = val;
        }
      
        static
        {
          __$swapInit();
          long l1 = 0L;
          __timeStamp__239_neverHappen1367381386616 = l1;
          long l2 = 1367381386616L;
        }
      }
      

      The method doesn't really do anything.

      Attachments

        Activity

          People

            melix Cédric Champeau
            brownj Jeff Brown
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: