Error initializing static fields that refer to one another
<p>I think I've found an error in some of my code, though it doesn't appear to rear its head in all situations.  I'm hoping someone smarter than me can definitively say "Yes, this is an error", and better yet, to suggest an another alternative to my implementation.</p>

<p>I believe the source of the error is how the static fields of two classes are initialized; one (in <code>FooClass</code>) is initialized by referring to the other's field, and one (in <code>MyUtility</code>) is initialized by creating an object of type <code>Foo</code>.  Sorry that sounds off; explanation was never my strong point.</p>

<p>I've spent the better part of a day trying to reduce the problem, and have something runnable that appears to demonstrate the problem.</p>

<pre class="lang-java prettyprint-override"><code>public class Tester {

    static class FooClass {
        static final FooClass ITS_FOO = MyUtility.MY_FOO;
    }

    static class MyUtility {
        static final FooClass MY_FOO = new FooClass();

        static FooClass create() {
            return new FooClass();
        }
    }

    public static void main(String[] args) {
        System.out.println("utility's: " + MyUtility.create()); // Line "A"
        System.out.println("class's:   " + FooClass.ITS_FOO);   // Line "B"
    }
}
</code></pre>

<p>I realize this design looks odd, but won't try to justify it much (the real code is structured "oddly" too, but within separate classes with different visibility etc).  I would definitely appreciate suggestions for better ways to do this.</p>

<p>The gist of the problem (at least with this program) is that the <code>FooClass.ITS_FOO</code> field is <code>null</code> when line B executes.  If I switch the order of lines A and B, neither of the fields are <code>null</code>.</p>

<p>I've seen questions like <a href="http://stackoverflow.com/questions/2007666/in-what-order-do-static-initializer-blocks-in-java-run">In what order do static initializer blocks in Java run?</a>, but neither that nor the <a href="http://docs.oracle.com/javase/specs/jls/se7/html/jls-12.html#jls-12.4" rel="nofollow">Java Language Spec</a> appear to describe how this kind of mutually referential initialization is done.</p>

<p>Unfortunately, this sample is so far removed from our real implementation that I'll probably spend the same amount of time translating any solution back, but that will be worth it to get some explanation.</p>
