-
Bug
-
Resolution: Not an Issue
-
P4
-
None
-
11, 17, 21, 25, 26
When an app creates a custom class loader to load and invoke its own main class, causing recursive re-execution, it throws:
'Exception: java.lang.NoClassDefFoundError thrown from the UncaughtExceptionHandler in thread “main"'
This misleading error arises due to secondary class initialisation failures during error reporting, triggered when the JVM attempts to print the original StackOverflowError’s via printStackTrace().
The behaviour is reproducible as far back as JDK 9, with JDK 8 printing the expected SOE.
Run the below class to reproduce:
public class B1903 {
public static void main(String[] args) {
try {
ClassLoader customLoader = new ClassLoader() { };
Class<?> clazz = customLoader.loadClass("B1903");
clazz.getDeclaredMethod("main", String[].class).invoke(null, (Object) args);
} catch (Exception e) {
e.printStackTrace();
}
}
}
'Exception: java.lang.NoClassDefFoundError thrown from the UncaughtExceptionHandler in thread “main"'
This misleading error arises due to secondary class initialisation failures during error reporting, triggered when the JVM attempts to print the original StackOverflowError’s via printStackTrace().
The behaviour is reproducible as far back as JDK 9, with JDK 8 printing the expected SOE.
Run the below class to reproduce:
public class B1903 {
public static void main(String[] args) {
try {
ClassLoader customLoader = new ClassLoader() { };
Class<?> clazz = customLoader.loadClass("B1903");
clazz.getDeclaredMethod("main", String[].class).invoke(null, (Object) args);
} catch (Exception e) {
e.printStackTrace();
}
}
}
- duplicates
-
JDK-8297586 Throwable.printStackTrace failing with StackOverflowError leads to NoClassDefFoundError
-
- Closed
-
-
JDK-8352070 Inconsistent Behavior in Recursive Method Invocation via Reflection on OpenJDK 8
-
- Closed
-