I just committed a fix to a bug caused by static field initialization
(YOKO-196). The bug was cause by a static initalizer calling a
static method which accessed a static field. I was getting a
NullPointerException because the static field was null because the
static field was declared after the initializer. For example:
public class Test {
static {
foo();
}
private static final Object bar = new Object();
private static void foo() {
System.out.println(bar);
}
public static void main(String[] args) throws Exception {
foo();
}
}
This problem type of problem is very difficult to find and is easily
avoided by putting all field declarations at the top of the file
followed by any static initializers.
What do you think of changing the coding standards to have all fields
at the top of the file?
-dain