groovy
  1. groovy
  2. GROOVY-5122

static fields on interface not getting initialized, when being initialized to an anonymous class instance

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.8.4
    • Fix Version/s: 1.8.5, 2.0-beta-2, 1.7.11
    • Component/s: None
    • Labels:
      None
    • Environment:
      OS X (suspected all)
    • Number of attachments :
      0

      Description

      The following code shows a static field on an interface not initialized at the point when the constructor of an instance of an implementing class is being run.

      
      package ignored.alex.failingcallsite
      
      import java.lang.reflect.Field;
      
      class FailingCallSiteLocalClass {
      	public static void main(String[] args) {
      		new B()		
      	}
      }
      
      interface A {
      	public static X x = new X() {
      		public void foo() {}
      	}
      }
      
      interface X {
      	void foo()
      }
      
      class B implements A {
      	public B() {
              for (Field f in getClass().getFields()) {
      			println f
      			println f.get(this)
      		}
      	}
      }
      

      Throws java.lang.IllegalAccessError when x is accessed via f.get(this).

      I would expect x to have been initialized by this point. Is there something subtle in when interfaces are initialized?

      There is no problem if A is a class extended by B, and more curiously, no problem if x is set equal to a named outer class (e.g. a class X2 implements X).

        Activity

        Hide
        CÚdric Champeau added a comment -

        Ok, so you are telling me that you don't have any IAE anymore ?

        Show
        CÚdric Champeau added a comment - Ok, so you are telling me that you don't have any IAE anymore ?
        Hide
        Alex Heneveld added a comment -

        Yep. All errors are gone – IAE for $..class, IAE for call site, duplicate class, missing constructor. Have tried several of the failure cases I had, and all are now happy. Strange that it would manifest itself in so many different ways, but all good now.

        Show
        Alex Heneveld added a comment - Yep. All errors are gone – IAE for $..class, IAE for call site, duplicate class, missing constructor. Have tried several of the failure cases I had, and all are now happy. Strange that it would manifest itself in so many different ways, but all good now.
        Hide
        CÚdric Champeau added a comment -

        Ok, last check. When you say you don't have any errors, is it with or without the patch (which is not committed) on AsmClassGenerator ?

        Show
        CÚdric Champeau added a comment - Ok, last check. When you say you don't have any errors, is it with or without the patch (which is not committed) on AsmClassGenerator ?
        Hide
        Alex Heneveld added a comment -

        The patch makes no apparent difference. I get no errors without it, and I get no errors with it.

        Show
        Alex Heneveld added a comment - The patch makes no apparent difference. I get no errors without it, and I get no errors with it.
        Hide
        CÚdric Champeau added a comment -

        Great, thanks!

        Show
        CÚdric Champeau added a comment - Great, thanks!

          People

          • Assignee:
            CÚdric Champeau
            Reporter:
            Alex Heneveld
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: