Skip to content

Fix NoSuchMethodException for Class.forName0 on Java 26#75

Open
arouel wants to merge 1 commit intotoolfactory:mainfrom
arouel:issue-74
Open

Fix NoSuchMethodException for Class.forName0 on Java 26#75
arouel wants to merge 1 commit intotoolfactory:mainfrom
arouel:issue-74

Conversation

@arouel
Copy link
Copy Markdown

@arouel arouel commented Mar 20, 2026

Problem

In JDK 26, the caller-sensitive logic for Class.forName was refactored so the classloader is resolved on the Java side before calling the native method. As a result, Class.forName0 dropped its fourth Class<?> caller parameter. This breaks GetClassByNameFunction$ForJava7, which uses MethodHandles to look up the old 4-parameter signature, causing a NoSuchMethodException at runtime on JDK 26 (see issue #74).

What

Adds a ForJava26 inner class that looks up forName0 with the new 3-parameter signature (String, boolean, ClassLoader), adds 26 to CRITICAL_VERSIONS, and extends the CI matrix to cover JDK 25 and 26.

In Java 26, the internal method Class.forName0 had its signature changed from:
```java
Class.forName0(String, boolean, ClassLoader, Class)  // 4 params - caller removed
```

to:
```java
Class.forName0(String, boolean, ClassLoader)          // 3 params
```

The `caller` parameter was removed because the caller-sensitive logic was refactored to resolve the classloader on the Java side before calling the native method.

The existing `GetClassByNameFunction$ForJava7` tried to look up the old 4-parameter signature via `MethodHandles`, which threw `NoSuchMethodException` on Java 26.

1. `GetClassByNameFunction.java:99-121` - Added a new `ForJava26` inner class that:
- Looks up `forName0` with the new 3-parameter signature `(String, boolean, ClassLoader)`
- Ignores the caller parameter in `apply()` since it's no longer needed
2. `Info.java:34` - Added `26` to `CRITICAL_VERSIONS` so the ObjectProvider will discover and use `ForJava26` when running on JDK 26+.
@arouel arouel changed the title Fix issue #74 Fix NoSuchMethodException for Class.forName0 on Java 26+ Mar 20, 2026
@arouel arouel changed the title Fix NoSuchMethodException for Class.forName0 on Java 26+ Fix NoSuchMethodException for Class.forName0 on Java 26 (fixes #74) Mar 20, 2026
@arouel arouel changed the title Fix NoSuchMethodException for Class.forName0 on Java 26 (fixes #74) Fix NoSuchMethodException for Class.forName0 on Java 26 Mar 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant