You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
@Async event listener suspending function throws IllegalArgumentException #36214
Spring Framework 7.0.3
Java 17
Kotlin 2.2.21 (Coroutines 1.10.2)
While asynchronously handling an event, a suspending function throws IllegalArgumentException as follows:
java.lang.IllegalArgumentException: Invalid return type for async method (only Future and void supported): class java.lang.Object
at org.springframework.aop.interceptor.AsyncExecutionAspectSupport.doSubmit(AsyncExecutionAspectSupport.java:290) ~[spring-aop-7.0.3.jar:7.0.3]
at org.springframework.aop.interceptor.AsyncExecutionInterceptor.invoke(AsyncExecutionInterceptor.java:127) ~[spring-aop-7.0.3.jar:7.0.3]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-7.0.3.jar:7.0.3]
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:719) ~[spring-aop-7.0.3.jar:7.0.3]
at com.example.demo.EventHandler$$SpringCGLIB$$0.handleCustomEventFail(<generated>) ~[classes/:na]
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:565) ~[na:na]
We can workaround it by using a coroutine builder function, such as CoroutineScope.launch(), to explicitly start a coroutine, but it would be great if @Async works seamlessly with suspending functions.
It is indeed redundant for Reactive types or suspending function, so here I would advise to not use @Async. That said, we can likely refine the error message to provide better guidance, so I will refine that.
Activity
joaodias14 commentedon Jan 26, 2026
I am now wondering: is it redundant to use
@Asyncon an event listener suspending function?sdeleuze commentedon Jan 29, 2026
It is indeed redundant for Reactive types or suspending function, so here I would advise to not use
@Async. That said, we can likely refine the error message to provide better guidance, so I will refine that.joaodias14 commentedon Jan 29, 2026
Thanks for the feedback @sdeleuze !