Skip to content

Commit dc8d694

Browse files
committed
Make Kotlin suspend function checks ClassLoader agnostic
This is done because with the current version of the code, in order for a method to consider a Kotlin suspending method, Kotlin and the test class need to be loaded from the same ClassLoader, but in Quarkus that is not the case Relates to: quarkusio/quarkus#52480 Signed-off-by: Georgios Andrianakis <geoand@gmail.com>
1 parent 223e5c7 commit dc8d694

2 files changed

Lines changed: 17 additions & 4 deletions

File tree

junit-platform-commons/src/main/java/org/junit/platform/commons/util/KotlinFunctionUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class KotlinFunctionUtils {
4141

4242
static Class<?> getReturnType(Method method) {
4343
var returnType = getJavaClass(getJvmErasure(getKotlinFunction(method).getReturnType()));
44-
if (Unit.class.equals(returnType)) {
44+
if (Unit.class.getName().equals(returnType.getName())) {
4545
return void.class;
4646
}
4747
return returnType;

junit-platform-commons/src/main/java/org/junit/platform/commons/util/KotlinReflectionUtils.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public static boolean isKotlinSuspendingFunction(Method method) {
7878
if (!method.isSynthetic() && kotlinCoroutineContinuation != null && isKotlinType(method.getDeclaringClass())) {
7979
int parameterCount = method.getParameterCount();
8080
return parameterCount > 0 //
81-
&& method.getParameterTypes()[parameterCount - 1] == kotlinCoroutineContinuation;
81+
&& kotlinCoroutineContinuation.getName().equals(method.getParameterTypes()[parameterCount - 1].getName());
8282
}
8383
return false;
8484
}
@@ -127,8 +127,21 @@ private static Class<?>[] copyWithoutFirst(Class<?>[] values) {
127127

128128
@API(status = INTERNAL, since = "6.1")
129129
public static boolean isKotlinType(Class<?> clazz) {
130-
return kotlinMetadata != null //
131-
&& clazz.getDeclaredAnnotation(kotlinMetadata) != null;
130+
if (kotlinMetadata == null) {
131+
return false;
132+
}
133+
134+
if (clazz.getClassLoader().equals(kotlinMetadata.getClassLoader())) {
135+
return clazz.getDeclaredAnnotation(kotlinMetadata) != null;
136+
} else {
137+
try {
138+
@SuppressWarnings("unchecked") Class<? extends Annotation> kotlinMetadataFromProperCL = (Class<? extends Annotation>) Class.forName(kotlinMetadata.getName(), false, clazz.getClassLoader());
139+
return clazz.getDeclaredAnnotation(kotlinMetadataFromProperCL) != null;
140+
}
141+
catch (Exception ignored) {
142+
return false;
143+
}
144+
}
132145
}
133146

134147
@API(status = INTERNAL, since = "6.1")

0 commit comments

Comments
 (0)