8000 In graalvm-jdk-21.0.5+9.1, an unknown error occurs when running a simple Java program · Issue #10994 · oracle/graal · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
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 · 6 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?

@selhagani
Copy link
Member

I tested the reproducer you shared with the latest versions of GraalVM for JDK 17 and for JDK 21. When using the latest versions, the output errors aren't that different.
They both fail with the following error Exception: java.lang.NoClassDefFoundError thrown from the UncaughtExceptionHandler in thread "main" Which leads me to believe that this isn't really a regression.
You mentioned that when using GraalVM for jdk 17 you get a StackOverflowError. could you please share with me the exact version in which you seem to be getting that error please?

@xwqmary
Copy link
Author
xwqmary commented Apr 29, 2025

@selhagani Thank you very much for looking into this issue.

The version I'm using is:
java version "17.0.13" 2024-10-15 LTS
Java(TM) SE Runtime Environment Oracle GraalVM 17.0.13+10.1 (build 17.0.13+10-LTS-jvmci-23.0-b49)
Java HotSpot(TM) 64-Bit Server VM Oracle GraalVM 17.0.13+10.1 (build 17.0.13+10-LTS-jvmci-23.0-b49, mixed mode, sharing)

@selhagani
Copy link
Member

Hi @xwqmary,

Thank you for sharing the exact version with me. After conducting further testing, I don't believe this is a regression. In fact, if you add the following line to the code:

System.out.println("Inside the main method");

You’ll see that recursion does occur in all versions.

@xwqmary
Copy link
Author
xwqmary commented May 10, 2025

Hi @selhagani
Thanks for confirming the reproduction. I suspect an internal mechanism flaw: although the recursion proceeds as expected, the JVM ends up throwing a NoClassDefFoundError instead of the expected StackOverflowError, which is clearly unreasonable.

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
0