Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
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 :
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).