Treat kotlin.Unit as void in web controllers
This commit fixes a regression introduced by gh-21139 via the usage of Kotlin reflection to invoke HTTP handler methods. It ensures that kotlin.Unit is treated as void by returning null. It also polishes CoroutinesUtils to have a consistent handling compared to the regular case, and adds related tests to prevent future regressions. Closes gh-31648
This commit is contained in:
@@ -71,6 +71,19 @@ class InvocableHandlerMethodKotlinTests {
|
||||
Assertions.assertThat(value).isEqualTo("true")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun unitReturnValue() {
|
||||
val value = getInvocable().invokeForRequest(request, null)
|
||||
Assertions.assertThat(value).isNull()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun nullReturnValue() {
|
||||
composite.addResolver(StubArgumentResolver(String::class.java, null))
|
||||
val value = getInvocable(String::class.java).invokeForRequest(request, null)
|
||||
Assertions.assertThat(value).isNull()
|
||||
}
|
||||
|
||||
private fun getInvocable(vararg argTypes: Class<*>): InvocableHandlerMethod {
|
||||
val method = ResolvableMethod.on(Handler::class.java).argTypes(*argTypes).resolveMethod()
|
||||
val handlerMethod = InvocableHandlerMethod(Handler(), method)
|
||||
@@ -95,6 +108,14 @@ class InvocableHandlerMethodKotlinTests {
|
||||
|
||||
fun nullableBooleanDefaultValue(status: Boolean? = true) =
|
||||
status.toString()
|
||||
|
||||
fun unit(): Unit {
|
||||
}
|
||||
|
||||
@Suppress("UNUSED_PARAMETER")
|
||||
fun nullable(arg: String?): String? {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user