11/*
2- * Copyright 2002-2021 the original author or authors.
2+ * Copyright 2002-2022 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
@@ -129,15 +129,16 @@ public void setReactiveAdapterRegistry(ReactiveAdapterRegistry registry) {
129129 * @param providedArgs optional list of argument values to match by type
130130 * @return a Mono with a {@link HandlerResult}
131131 */
132- @ SuppressWarnings ("KotlinInternalInJava" )
132+ @ SuppressWarnings ({ "KotlinInternalInJava" , "unchecked" } )
133133 public Mono <HandlerResult > invoke (
134134 ServerWebExchange exchange , BindingContext bindingContext , Object ... providedArgs ) {
135135
136136 return getMethodArgumentValues (exchange , bindingContext , providedArgs ).flatMap (args -> {
137137 Object value ;
138+ Method method = getBridgedMethod ();
139+ boolean isSuspendingFunction = KotlinDetector .isSuspendingFunction (method );
138140 try {
139- Method method = getBridgedMethod ();
140- if (KotlinDetector .isSuspendingFunction (method )) {
141+ if (isSuspendingFunction ) {
141142 value = CoroutinesUtils .invokeSuspendingFunction (method , getBean (), args );
142143 }
143144 else {
@@ -163,10 +164,16 @@ public Mono<HandlerResult> invoke(
163164 }
164165
165166 MethodParameter returnType = getReturnType ();
166- ReactiveAdapter adapter = this .reactiveAdapterRegistry .getAdapter (returnType .getParameterType ());
167- boolean asyncVoid = isAsyncVoidReturnType (returnType , adapter );
168- if ((value == null || asyncVoid ) && isResponseHandled (args , exchange )) {
169- return (asyncVoid ? Mono .from (adapter .toPublisher (value )) : Mono .empty ());
167+ if (isResponseHandled (args , exchange )) {
168+ Class <?> parameterType = returnType .getParameterType ();
169+ ReactiveAdapter adapter = this .reactiveAdapterRegistry .getAdapter (parameterType );
170+ boolean asyncVoid = isAsyncVoidReturnType (returnType , adapter );
171+ if (value == null || asyncVoid ) {
172+ return (asyncVoid ? Mono .from (adapter .toPublisher (value )) : Mono .empty ());
173+ }
174+ if (isSuspendingFunction && parameterType == void .class ) {
175+ return (Mono <HandlerResult >) value ;
176+ }
170177 }
171178
172179 HandlerResult result = new HandlerResult (this , value , returnType , bindingContext );
0 commit comments