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

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

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.8.4
    • 1.8.5, 2.0-beta-2, 1.7.11
    • None
    • None
    • OS X (suspected all)

    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).

      Attachments

        Issue Links

          Activity

            People

              melix Cédric Champeau
              alex.heneveld Alex Heneveld
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: