From 9ccac0987c05694e9b3ff60e7429bc4867f101aa Mon Sep 17 00:00:00 2001 From: Patrick Ziegler Date: Tue, 1 Apr 2025 19:11:06 +0200 Subject: [PATCH] Make Class.forName work with null caller class --- .../src/com/oracle/svm/core/hub/DynamicHub.java | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/hub/DynamicHub.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/hub/DynamicHub.java index 68d87ec69778..a4d9b0373cc5 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/hub/DynamicHub.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/hub/DynamicHub.java @@ -85,7 +85,6 @@ import org.graalvm.nativeimage.Platform; import org.graalvm.nativeimage.Platforms; import org.graalvm.nativeimage.c.function.CFunctionPointer; -import org.graalvm.nativeimage.impl.InternalPlatform; import com.oracle.svm.core.BuildPhaseProvider.AfterHostedUniverse; import com.oracle.svm.core.BuildPhaseProvider.CompileQueueFinished; @@ -1567,28 +1566,24 @@ private static Constructor[] copyConstructors(Constructor[] original) { private native Constructor getEnclosingConstructor(); @Substitute - @Platforms(InternalPlatform.NATIVE_ONLY.class) @CallerSensitive private static Class forName(String className) throws Throwable { return forName(className, Reflection.getCallerClass()); } @Substitute - @Platforms(InternalPlatform.NATIVE_ONLY.class) @CallerSensitiveAdapter private static Class forName(String className, Class caller) throws Throwable { - return forName(className, true, caller.getClassLoader(), caller); + return forName(className, true, caller == null ? ClassLoader.getSystemClassLoader() : caller.getClassLoader(), caller); } @Substitute - @Platforms(InternalPlatform.NATIVE_ONLY.class) @CallerSensitive private static Class forName(Module module, String className) throws Throwable { return forName(module, className, Reflection.getCallerClass()); } @Substitute - @Platforms(InternalPlatform.NATIVE_ONLY.class) @CallerSensitiveAdapter @TargetElement(onlyWith = JDK21OrEarlier.class) private static Class forName(@SuppressWarnings("unused") Module module, String className, Class caller) throws Throwable {