Merge branch '6.1.x'
This commit is contained in:
@@ -353,9 +353,10 @@ public abstract class AopUtils {
|
|||||||
|
|
||||||
// Use reflection to invoke the method.
|
// Use reflection to invoke the method.
|
||||||
try {
|
try {
|
||||||
ReflectionUtils.makeAccessible(method);
|
Method originalMethod = BridgeMethodResolver.findBridgedMethod(method);
|
||||||
return (coroutinesReactorPresent && KotlinDetector.isSuspendingFunction(method) ?
|
ReflectionUtils.makeAccessible(originalMethod);
|
||||||
KotlinDelegate.invokeSuspendingFunction(method, target, args) : method.invoke(target, args));
|
return (coroutinesReactorPresent && KotlinDetector.isSuspendingFunction(originalMethod) ?
|
||||||
|
KotlinDelegate.invokeSuspendingFunction(originalMethod, target, args) : originalMethod.invoke(target, args));
|
||||||
}
|
}
|
||||||
catch (InvocationTargetException ex) {
|
catch (InvocationTargetException ex) {
|
||||||
// Invoked method threw a checked exception.
|
// Invoked method threw a checked exception.
|
||||||
|
|||||||
@@ -34,19 +34,48 @@ class AopUtilsKotlinTests {
|
|||||||
@Test
|
@Test
|
||||||
fun `Invoking suspending function should return Mono`() {
|
fun `Invoking suspending function should return Mono`() {
|
||||||
val value = "foo"
|
val value = "foo"
|
||||||
val method = ReflectionUtils.findMethod(AopUtilsKotlinTests::class.java, "suspendingFunction",
|
val method = ReflectionUtils.findMethod(WithoutInterface::class.java, "handle",
|
||||||
String::class.java, Continuation::class.java)!!
|
String::class. java, Continuation::class.java)!!
|
||||||
val continuation = Continuation<Any>(CoroutineName("test")) { }
|
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(result).isInstanceOfSatisfying(Mono::class.java) {
|
||||||
assertThat(it.block()).isEqualTo(value)
|
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")
|
@Suppress("unused")
|
||||||
suspend fun suspendingFunction(value: String): String {
|
suspend fun suspendingFunction(value: String): String {
|
||||||
delay(1)
|
delay(1)
|
||||||
return value
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user