Quicktip
If a class fails to load due to an exception during class initialization, the actual problem is only logged the first time you attempt to load the class. After the first time, the classloader recognizes that it’s already tried to load the class and just throws a ClassNotFoundException or NoClassDefFoundError.
Symptom
You will see logs for the ClassNotFoundException or NoClassDefFoundError (usually many such logs), but you see that the class is in the classpath. You won’t see any root cause on any stack trace but the first (and that one is typically not a CNFE or NCDFE).
Finding the root cause
If you get a CNFE or NCDFE and you see the class in the classpath, search back your logs for ${missing classname}.<clinit> in a stack trace to figure out what prevented the class from being loaded. Remember that the log may have rolled off.
Possible root causes for CNFE/NCDFE
- Desired class is not in classpath (this is the boring case)
- Initialization of desired class throws a RuntimeException or an Error
- Static variable is initialized via a function which threw an uncaught Throwable
- E.g. public static final String SOME_CONST = SomeClass.getString(“SOME_KEY”); where SomeClass.getString(String key) can throw an Exception.
- Static block (loose code in {} in the class definition) threw an uncaught Throwable
- E.g. public class Foo { { doSomeStaticInitialization(); } …
- variable or method signature includes type which could not be initialized (see this same list of root causes)
- E.g. public class Foo { SomeClassWithErrorInInitializer attr1; …
From The SDE Tip – Amazon
Popularity: 1% [?]