I can't answer the question directly but I can tell you the rule to avoid breaking.
* Do not call an overridable method from a constructor. This is because the method may rely on state that has not been set yet because the constructor has not yet run. Remember that the superclass' constructor happens before the subclass'. Stick to this rule and you'll generally stop observing the state of a final pre-initialisation. On Mon, Nov 22, 2010 at 4:53 PM, Craig Kelley <[email protected]> wrote: > Hello Java Posse. > > In a break from Oracle and Google legal fun, I thought I'd throw this > problem out there. We're running into a strange, what seems to be JVM- > related issue. Given the following classes: > > abstract class Inner { > Inner() { run(); } > public abstract void run(); > } > > public class Outer { > public static void test(final String s) { > Inner i = new Inner() { > public void run() { > System.out.println("s = " + s); > } > }; > i.run(); > } > > public static void main(String[] args) { > test("hello"); > } > } > > Why does jre 1.4 return this: > > s = null > s = hello > > But jre 6 returns this: > > s = hello > s = hello > > We have an application targeting jre6 that is getting null pointer > exceptions from variables supposedly declared final, referenced from > inner classes. > > -- > You received this message because you are subscribed to the Google Groups > "The Java Posse" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]<javaposse%[email protected]> > . > For more options, visit this group at > http://groups.google.com/group/javaposse?hl=en. > > -- You received this message because you are subscribed to the Google Groups "The Java Posse" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/javaposse?hl=en.
