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

static inner classes are not being compiled correctly

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Blocker
    • Resolution: Fixed
    • 1.7.6, 1.8-beta-3
    • 1.8-rc-1, 1.7.9
    • Compiler
    • None

    Description

      The groovy compiler used by eclipse & intellij are both having trouble compiling static inner classes. The groovyc compiler does not fail but it appears to generate incorrect bytecode. I filed a issue with intellij and they said that this is a groovy compiler problem not and intellij problem.

      The following code triggers the problem:

      //groovy code
      class Outer {
        static class Inner {}
      }
      
      //java code
      public class Client {
        { new Outer.Inner(); }
      }
      

      This is a serious issue because without any tool support we cannot use static inner classes. The only work around for this issue is to not use static inner classes.

      Here are the following issues related to this:

      http://jira.codehaus.org/browse/GRECLIPSE-983
      http://youtrack.jetbrains.net/issue/IDEA-64752
      http://youtrack.jetbrains.net/issue/IDEA-50708

      I have not looked in detail at the bytecode generated by the groovy compiler but decompiling the class files with JD Decompiler gives the following:

      //notice no reference to the Inner class.  Decompiling a java compiled class like this will show the Inner class in the Outer class.
      public class Outer
        implements GroovyObject
      {
        public Outer()
        {
          Outer this;
          CallSite[] arrayOfCallSite = $getCallSiteArray();
          MetaClass localMetaClass = $getStaticMetaClass();
          this.metaClass = localMetaClass;
        }
      
        static
        {
          Long localLong1 = (Long)DefaultTypeTransformation.box(0L);
          __timeStamp__239_neverHappen1296229343062 = DefaultTypeTransformation.longUnbox(localLong1);
          Long localLong2 = (Long)DefaultTypeTransformation.box(1296229343062L);
          __timeStamp = DefaultTypeTransformation.longUnbox(localLong2);
        }
      }
      

      Attachments

        Activity

          People

            blackdrag Jochen Theodorou
            leo.herbie Travis Schneeberger
            Votes:
            4 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: