Calls to inner class super constructor and putfield
Gordon Syme
gordon at twiceasgood.net
Fri Sep 25 05:35:51 PDT 2009
On Thu, 2009-09-24 at 10:18 -0700, John Rose wrote:
> 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.
Thanks for the reply John, that makes a lot of sense. I hadn't even
considered virtual calls from the superclass ctor!
Much appreciated
-Gordon
More information about the compiler-dev
mailing list