-
Enhancement
-
Resolution: Fixed
-
P4
-
7u60, 8, 11, 15, 17
-
b11
-
x86_64
-
linux
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8297356 | 17.0.7-oracle | Calvin Cheung | P4 | Resolved | Fixed | b01 |
JDK-8303556 | 17.0.7 | Goetz Lindenmaier | P4 | Resolved | Fixed | b05 |
JDK-8298049 | 11.0.19-oracle | Calvin Cheung | P4 | Resolved | Fixed | b01 |
JDK-8298857 | 8u371 | Poonam Bajaj Parhar | P4 | Resolved | Fixed | b04 |
JDK-8301173 | 8u361 | Dukebot | P4 | Closed | Fixed | b32 |
JDK-8301364 | 8u341 | Dukebot | P4 | Closed | Fixed | b33 |
It is common for various subtle bugs in software, or configuration issues on certain machines, to cause a static initializer to fail, which produces a ExceptionInInitializerError. If this error is caught and logged to appropriate channels then the application developer or support person can easily track down the problem, and normally that is what happens.
However on occasion the ExceptionInInitializerError is swallowed due to buggy error handling code, which might be difficult or impossible to locate in a large modular application. If this happens, subsequent references to the problematic class throw a NoClassDefFoundError, yet omit any information about *why* the class could not be loaded; this information is apparently unreconstructible.
Related to
JUSTIFICATION :
Crucial for field diagnosis of complex errors. I have personally encountered this problem on a number of occasions and spent a lot of time tracking down the root cause. (In the current case I am unable to find the original error at all, and the problem has disappeared after a JVM restart so cannot be reproduced.)
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
When an ExceptionInInitializerError is thrown, this error ought to be saved in class metadata by the JVM, and used as a NoClassDefFoundError.cause if any subsequent attempts to load the class are made.
ACTUAL -
There is no cause in the NoClassDefFoundError, and the detail message gives little information beyond the name of the class and the implication that an ExceptionInInitializerError was involved.
---------- BEGIN SOURCE ----------
public class Demo {
public static void main(String[] args) throws Exception {
try {
new X();
} catch (LinkageError x) {
// ignore
}
new X();
}
public static final class X {
static {
if (X.class != null) {
throw new IllegalStateException("Oops!");
}
}
}
}
on JDK 7u60 or 8u0 produces simply:
Exception in thread "main" java.lang.NoClassDefFoundError: Could not initialize class Demo$X
at Demo.main(Demo.java:8)
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
None known, other than somehow tracking down the original ExceptionInInitializerError from some earlier log if it was ever recorded at all.
- backported by
-
JDK-8297356 NoClassDefFoundError omits original ExceptionInInitializerError
- Resolved
-
JDK-8298049 NoClassDefFoundError omits original ExceptionInInitializerError
- Resolved
-
JDK-8298857 NoClassDefFoundError omits original ExceptionInInitializerError
- Resolved
-
JDK-8303556 NoClassDefFoundError omits original ExceptionInInitializerError
- Resolved
-
JDK-8301173 NoClassDefFoundError omits original ExceptionInInitializerError
- Closed
-
JDK-8301364 NoClassDefFoundError omits original ExceptionInInitializerError
- Closed
- relates to
-
JDK-8257534 misc tests failed with "NoClassDefFoundError: Could not initialize class java.util.concurrent.ThreadLocalRandom"
- Resolved
-
JDK-8309034 NoClassDefFoundError when initializing Long$LongCache
- Resolved
-
JDK-8302491 NoClassDefFoundError omits the original cause of an error
- Resolved
-
JDK-8291458 Hotspot execute a correct test cases and report NoClassDefFoundError
- Closed
- links to
-
Commit openjdk/jdk17u-dev/bf513540
-
Commit openjdk/jdk/464e874a
-
Review openjdk/jdk17u-dev/1195
-
Review openjdk/jdk/4996