diff --git a/experimental/types/src/main/java/io/serverlessworkflow/api/types/utils/ReflectionUtils.java b/experimental/types/src/main/java/io/serverlessworkflow/api/types/utils/ReflectionUtils.java index 536f9b3bb..2e1529a92 100644 --- a/experimental/types/src/main/java/io/serverlessworkflow/api/types/utils/ReflectionUtils.java +++ b/experimental/types/src/main/java/io/serverlessworkflow/api/types/utils/ReflectionUtils.java @@ -100,6 +100,10 @@ public static Class loadCapturingClass(String capturingClass) throws ClassNot } public static Class loadClass(String className) throws ClassNotFoundException { + return Class.forName(className, false, getClassLoader()); + } + + private static ClassLoader getClassLoader() { ClassLoader cl = Thread.currentThread().getContextClassLoader(); if (cl == null) { cl = ReflectionUtils.class.getClassLoader(); @@ -107,7 +111,7 @@ public static Class loadClass(String className) throws ClassNotFoundException cl = ClassLoader.getSystemClassLoader(); } } - return cl.loadClass(className); + return cl; } public static Object functionFromSerialized(SerializedLambda sl) @@ -126,8 +130,7 @@ public static Optional methodType(Object fn) { public static MethodType inferMethodType(SerializedLambda sl) { // getInstantiatedMethodType() provides the exact generic signature resolved // by the compiler, completely bypassing captured variables and method kind switches! - return MethodType.fromMethodDescriptorString( - sl.getInstantiatedMethodType(), sl.getClass().getClassLoader()); + return MethodType.fromMethodDescriptorString(sl.getInstantiatedMethodType(), getClassLoader()); } public static SerializedLambda serializedLambda(Object fn)