Details
-
Bug
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
1.8.3
-
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.