Skip to content

In graalvm-jdk-21.0.5+9.1, an unknown error occurs when running a simple Java program #10994

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
xwqmary opened this issue Apr 7, 2025 · 2 comments
Assignees
Labels

Comments

@xwqmary
Copy link

xwqmary commented Apr 7, 2025

In graalvm-jdk-21.0.5+9.1, a Java program encounters an unexpected java.lang.NoClassDefFoundError: Could not initialize class java.lang.StackTraceElement$HashedModules despite the class B1903 being successfully loaded at startup by the system class loader (AppClassLoader). The program uses a custom ClassLoader to load B1903 and invokes its main method via reflection, leading to limited recursion before failing with this error. Since B1903 is already loaded as the entry point class, the NoClassDefFoundError seems unjustified. In contrast, the same code on graalvm-jdk-17 runs as expected, entering full recursion and throwing StackOverflowError without this issue.

Steps to reproduce the issue

testcase

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();
       }
   }
}

graalvm-jdk-21.0.5+9.1/bin/javac B1903.java

graalvm-jdk-21.0.5+9.1/bin/java B1903

output:

Exception in thread "main" java.lang.NoClassDefFoundError: Could not initialize class java.lang.StackTraceElement$HashedModules

Exception: java.lang.NoClassDefFoundError thrown from the UncaughtExceptionHandler in thread "main"

On graalvm-jdk-17, the same code recurses fully until a StackOverflowError, as expected. In graalvm-jdk-21.0.5+9.1, the recursion stops prematurely with NoClassDefFoundError, referencing StackTraceElement$HashedModules. Since B1903 is already loaded and accessible, this error is unexpected and suggests a failure in an internal JVM class during recursion, not a problem with B1903 itself. I believe this could indicate a latent issue in GraalVM JDK 21, possibly related to stricter runtime checks or a regression in handling recursive reflection calls.

@xwqmary xwqmary added the bug label Apr 7, 2025
@selhagani selhagani self-assigned this Apr 8, 2025
@selhagani
Copy link
Member

Hi @xwqmary,

Thank you for reaching out to us!
I was able to reproduce the issue you reported on my end. We will take a closer look into this and I'll make sure to keep you updated.

@MrTommyt
Copy link

Hello @selhagani I also encountered this issue, have you got any leads into the cause of the problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants