I have the below method in class A. All classes A,B,C and the main class from which 'A' is invoked are in the same jar.
public class A {
private static void init() {
if (!init) {
synchronized (B.class) {
if (!init) {
map = C.creat();
init = true;
}
}
}
}
}
The code is throwing a Throwable
, java.lang.NoClassDefFoundError
at the synchronized
block (Line no.4).
What can be the reason as all the classes are in the same jar, there is no chance for not finding a class during run time.
I have gone through the solution in Existing Question but could not find a solution. Please help.
There are static initialization blocks and static variables in class B.
The issue can be fixed, if I use a static object/class A
to Synchronize the piece of code instead of 'B'. I am curious to know why i faced the exception and how to fix it using class B only.