Calls to inner class super constructor and putfield

John Rose John.Rose at Sun.COM
Thu Sep 24 10:18:12 PDT 2009

On Sep 23, 2009, at 3:38 AM, Gordon Syme wrote:

> I have noticed that when an inner class is compiled the call to store
> the outer class instance reference in the synthetic 'this$n' field
> occurs before the call to the inner class's super constructor.

The initialization of uplevel links (e.g., this$0) needs to be done  
before the superclass constructor call, because the superclass  
constructor can sometimes call a virtual method on the subclass.  This  
was an original bug in inner classes, leading to surprising NPEs  
coming out of uplevel references.  We couldn't fix the bug until the  
verifier was liberalized slightly (and safely) to allow fields to be  
initialized before the constructor call.

-- John

More information about the compiler-dev mailing list