|
34 | 34 | import javax.servlet.ServletException;
|
35 | 35 | import javax.servlet.http.HttpServletRequest;
|
36 | 36 |
|
| 37 | +import kotlin.reflect.KFunction; |
| 38 | +import kotlin.reflect.jvm.ReflectJvmMapping; |
| 39 | + |
37 | 40 | import org.springframework.aop.support.AopUtils;
|
38 | 41 | import org.springframework.beans.factory.BeanFactoryUtils;
|
39 | 42 | import org.springframework.beans.factory.InitializingBean;
|
| 43 | +import org.springframework.core.KotlinDetector; |
40 | 44 | import org.springframework.core.MethodIntrospector;
|
41 | 45 | import org.springframework.lang.Nullable;
|
42 | 46 | import org.springframework.util.Assert;
|
@@ -585,6 +589,10 @@ public void releaseReadLock() {
|
585 | 589 | }
|
586 | 590 |
|
587 | 591 | public void register(T mapping, Object handler, Method method) {
|
| 592 | + // Assert that the handler method is not a suspending one. |
| 593 | + if (KotlinDetector.isKotlinType(method.getDeclaringClass()) && KotlinDelegate.isSuspend(method)) { |
| 594 | + throw new IllegalStateException("Unsupported suspending handler method detected: " + method); |
| 595 | + } |
588 | 596 | this.readWriteLock.writeLock().lock();
|
589 | 597 | try {
|
590 | 598 | HandlerMethod handlerMethod = createHandlerMethod(handler, method);
|
@@ -793,4 +801,15 @@ public void handle() {
|
793 | 801 | }
|
794 | 802 | }
|
795 | 803 |
|
| 804 | + /** |
| 805 | + * Inner class to avoid a hard dependency on Kotlin at runtime. |
| 806 | + */ |
| 807 | + private static class KotlinDelegate { |
| 808 | + |
| 809 | + static private boolean isSuspend(Method method) { |
| 810 | + KFunction<?> function = ReflectJvmMapping.getKotlinFunction(method); |
| 811 | + return function != null && function.isSuspend(); |
| 812 | + } |
| 813 | + } |
| 814 | + |
796 | 815 | }
|
0 commit comments