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

Sometimes invalid inner class reference left in .class files produced for interfaces

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 1.8.3
    • 1.8.6, 2.0-beta-3
    • class generator
    • None

    Description

      Compile this:

      interface X {
        public String compute();
      }
      

      Upon javap'ing the result we see this InnerClass attribute:

      public interface X
        SourceFile: "X.groovy"
        InnerClass: 
         #10= #9 of #2; //"1"=class X$1 of class X
        minor version: 0
        major version: 47
        Constant pool:
      

      to X$1. But there is no X$1 produced on disk. Some environments (e.g. eclipse) are attempting to make sense of this and failing with a 'cant find type' message as they can't find the class file. groovy shouldn't be including these references. I believe a decision is made up front that one of these types will be created and then later a decision is taken that there is no need to produce one, but the original reference is left in the interface type (and so it is captured in the attribute).

      I changed two things to fix this:

      1. Added a method to ClassNode so that it could be told to forget about an interface like this:

          public void forgetInnerClass(InnerClassNode icn) {
              if (innerClasses!=null) {
              innerClasses.remove(icn);
              }
          }
      

      2. And then in the code that decides it doesn't need one (in AsmClassGenerator), forget is called so that the InnerClass attribute isn't added for it:

      protected void createInterfaceSyntheticStaticFields() {
          if (referencedClasses.isEmpty()) {
              controller.getClassNode().forgetInnerClass(controller.getInterfaceClassLoadingClass()); // my new line
              return;
          }
          ...
      

      this appears to fix it and continues to pass all the groovy tests.

      Attachments

        Activity

          People

            blackdrag Jochen Theodorou
            aclement Andy Clement
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: