Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Cannot Reproduce
-
1.5.5, 1.7.10, 1.8.4, 2.0.0
-
None
-
Linux 2.6.32-41-generic Ubuntu SMP i686
Description
When a class variable, which is initialized in a static block, is assigned to another static variable, the latter will stay null throughout execution.
The decompiled class file looks like this (verbosity omitted):
StaticInitializerBugGroovy.class
// ... public class StaticInitializerBug implements GroovyObject { private static String VAR1; private static String VAR2; // ... static { __$swapInit(); // ... String str1 = (String)VAR1; VAR2 = (String)str1; String str2 = "Hi."; VAR1 = str2; // ... } // ... }
I guess, the problem is clearly visible, as the swapping via temporary variables is done in the wrong order.
The same scenario written and compiled in Java 6 and then decompiled again produces the following:
StaticInitializerBugJava.class
public class StaticInitializerBug { static String VAR1; static String VAR2; // ... static { VAR1 = "Hi."; VAR2 = VAR1; } // ... }