1. If things go wrong, you get a cryptic exception in initializer(or something similar, I do not remember exactly) exception which does not give away much.
2. Prevents the class from being loaded, which prevents other classes which rely on this from being loaded, leading to a chain effect.

Take the example below:

class Foo {
  private static int bar = Moo.intValue(); 
}

class Moo {
  public static int intValue() {
    //parses data from an xml and returns it
  }
}

In the above, due to some reason let us assume that the xml is not present and this gets thrown as a run time exception from intValue. If this happens, it prevents the Foo class from being loaded by the JVM. If this code is running within a server and the server init code accesses this class, then the whole app is prevented from being loaded due to this. So, before using static initialization that depends on some other class, make sure you have assessed the possibility of your class not being loaded and how it affects your app.

Advertisements