Skip to content

Commit bb4a96f

Browse files
committed
Merge branch '6.1.x'
2 parents 4dcdd9a + 1911ca7 commit bb4a96f

File tree

2 files changed

+36
-6
lines changed

2 files changed

+36
-6
lines changed

spring-aop/src/main/java/org/springframework/aop/support/AopUtils.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -353,9 +353,10 @@ public static Object invokeJoinpointUsingReflection(@Nullable Object target, Met
353353

354354
// Use reflection to invoke the method.
355355
try {
356-
ReflectionUtils.makeAccessible(method);
357-
return (coroutinesReactorPresent && KotlinDetector.isSuspendingFunction(method) ?
358-
KotlinDelegate.invokeSuspendingFunction(method, target, args) : method.invoke(target, args));
356+
Method originalMethod = BridgeMethodResolver.findBridgedMethod(method);
357+
ReflectionUtils.makeAccessible(originalMethod);
358+
return (coroutinesReactorPresent && KotlinDetector.isSuspendingFunction(originalMethod) ?
359+
KotlinDelegate.invokeSuspendingFunction(originalMethod, target, args) : originalMethod.invoke(target, args));
359360
}
360361
catch (InvocationTargetException ex) {
361362
// Invoked method threw a checked exception.

spring-aop/src/test/kotlin/org/springframework/aop/support/AopUtilsKotlinTests.kt

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,48 @@ class AopUtilsKotlinTests {
3434
@Test
3535
fun `Invoking suspending function should return Mono`() {
3636
val value = "foo"
37-
val method = ReflectionUtils.findMethod(AopUtilsKotlinTests::class.java, "suspendingFunction",
38-
String::class.java, Continuation::class.java)!!
37+
val method = ReflectionUtils.findMethod(WithoutInterface::class.java, "handle",
38+
String::class. java, Continuation::class.java)!!
3939
val continuation = Continuation<Any>(CoroutineName("test")) { }
40-
val result = AopUtils.invokeJoinpointUsingReflection(this, method, arrayOf(value, continuation))
40+
val result = AopUtils.invokeJoinpointUsingReflection(WithoutInterface(), method, arrayOf(value, continuation))
4141
assertThat(result).isInstanceOfSatisfying(Mono::class.java) {
4242
assertThat(it.block()).isEqualTo(value)
4343
}
4444
}
4545

46+
@Test
47+
fun `Invoking suspending function on bridged method should return Mono`() {
48+
val value = "foo"
49+
val bridgedMethod = ReflectionUtils.findMethod(WithInterface::class.java, "handle", Object::class.java, Continuation::class.java)!!
50+
val continuation = Continuation<Any>(CoroutineName("test")) { }
51+
val result = AopUtils.invokeJoinpointUsingReflection(WithInterface(), bridgedMethod, arrayOf(value, continuation))
52+
assertThat(result).isInstanceOfSatisfying(Mono::class.java) {
53+
assertThat(it.block()).isEqualTo(value)
54+
}
55+
}
56+
4657
@Suppress("unused")
4758
suspend fun suspendingFunction(value: String): String {
4859
delay(1)
4960
return value
5061
}
5162

63+
class WithoutInterface {
64+
suspend fun handle(value: String): String {
65+
delay(1)
66+
return value
67+
}
68+
}
69+
70+
interface ProxyInterface<T> {
71+
suspend fun handle(value: T): T
72+
}
73+
74+
class WithInterface : ProxyInterface<String> {
75+
override suspend fun handle(value: String): String {
76+
delay(1)
77+
return value
78+
}
79+
}
80+
5281
}

0 commit comments

Comments
 (0)