Skip to content

Commit 51a3c7d

Browse files
authored
Using same classloader to load classes (#1527)
Priorizing ThreadContextClassLoader Signed-off-by: fjtirado <ftirados@ibm.com>
1 parent 6703f34 commit 51a3c7d

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

experimental/types/src/main/java/io/serverlessworkflow/api/types/utils/ReflectionUtils.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,18 @@ public static Class<?> loadCapturingClass(String capturingClass) throws ClassNot
100100
}
101101

102102
public static Class<?> loadClass(String className) throws ClassNotFoundException {
103+
return Class.forName(className, false, getClassLoader());
104+
}
105+
106+
private static ClassLoader getClassLoader() {
103107
ClassLoader cl = Thread.currentThread().getContextClassLoader();
104108
if (cl == null) {
105109
cl = ReflectionUtils.class.getClassLoader();
106110
if (cl == null) {
107111
cl = ClassLoader.getSystemClassLoader();
108112
}
109113
}
110-
return cl.loadClass(className);
114+
return cl;
111115
}
112116

113117
public static Object functionFromSerialized(SerializedLambda sl)
@@ -126,8 +130,7 @@ public static Optional<MethodType> methodType(Object fn) {
126130
public static MethodType inferMethodType(SerializedLambda sl) {
127131
// getInstantiatedMethodType() provides the exact generic signature resolved
128132
// by the compiler, completely bypassing captured variables and method kind switches!
129-
return MethodType.fromMethodDescriptorString(
130-
sl.getInstantiatedMethodType(), sl.getClass().getClassLoader());
133+
return MethodType.fromMethodDescriptorString(sl.getInstantiatedMethodType(), getClassLoader());
131134
}
132135

133136
public static SerializedLambda serializedLambda(Object fn)

0 commit comments

Comments
 (0)