Skip to content

Commit

Permalink
Merge branch '6.1.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
sdeleuze committed Aug 12, 2024
2 parents 4dcdd9a + 1911ca7 commit bb4a96f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -353,9 +353,10 @@ public static Object invokeJoinpointUsingReflection(@Nullable Object target, Met

// Use reflection to invoke the method.
try {
ReflectionUtils.makeAccessible(method);
return (coroutinesReactorPresent && KotlinDetector.isSuspendingFunction(method) ?
KotlinDelegate.invokeSuspendingFunction(method, target, args) : method.invoke(target, args));
Method originalMethod = BridgeMethodResolver.findBridgedMethod(method);
ReflectionUtils.makeAccessible(originalMethod);
return (coroutinesReactorPresent && KotlinDetector.isSuspendingFunction(originalMethod) ?
KotlinDelegate.invokeSuspendingFunction(originalMethod, target, args) : originalMethod.invoke(target, args));
}
catch (InvocationTargetException ex) {
// Invoked method threw a checked exception.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,48 @@ class AopUtilsKotlinTests {
@Test
fun `Invoking suspending function should return Mono`() {
val value = "foo"
val method = ReflectionUtils.findMethod(AopUtilsKotlinTests::class.java, "suspendingFunction",
String::class.java, Continuation::class.java)!!
val method = ReflectionUtils.findMethod(WithoutInterface::class.java, "handle",
String::class. java, Continuation::class.java)!!
val continuation = Continuation<Any>(CoroutineName("test")) { }
val result = AopUtils.invokeJoinpointUsingReflection(this, method, arrayOf(value, continuation))
val result = AopUtils.invokeJoinpointUsingReflection(WithoutInterface(), method, arrayOf(value, continuation))
assertThat(result).isInstanceOfSatisfying(Mono::class.java) {
assertThat(it.block()).isEqualTo(value)
}
}

@Test
fun `Invoking suspending function on bridged method should return Mono`() {
val value = "foo"
val bridgedMethod = ReflectionUtils.findMethod(WithInterface::class.java, "handle", Object::class.java, Continuation::class.java)!!
val continuation = Continuation<Any>(CoroutineName("test")) { }
val result = AopUtils.invokeJoinpointUsingReflection(WithInterface(), bridgedMethod, arrayOf(value, continuation))
assertThat(result).isInstanceOfSatisfying(Mono::class.java) {
assertThat(it.block()).isEqualTo(value)
}
}

@Suppress("unused")
suspend fun suspendingFunction(value: String): String {
delay(1)
return value
}

class WithoutInterface {
suspend fun handle(value: String): String {
delay(1)
return value
}
}

interface ProxyInterface<T> {
suspend fun handle(value: T): T
}

class WithInterface : ProxyInterface<String> {
override suspend fun handle(value: String): String {
delay(1)
return value
}
}

}

0 comments on commit bb4a96f

Please sign in to comment.