Merge branch '6.1.x'
This commit is contained in:
commit
dc982d0d51
|
@ -130,7 +130,11 @@ public abstract class CoroutinesUtils {
|
|||
KType type = parameter.getType();
|
||||
if (!(type.isMarkedNullable() && arg == null) && type.getClassifier() instanceof KClass<?> kClass
|
||||
&& KotlinDetector.isInlineClass(JvmClassMappingKt.getJavaClass(kClass))) {
|
||||
arg = KClasses.getPrimaryConstructor(kClass).call(arg);
|
||||
KFunction<?> constructor = KClasses.getPrimaryConstructor(kClass);
|
||||
if (!KCallablesJvm.isAccessible(constructor)) {
|
||||
KCallablesJvm.setAccessible(constructor, true);
|
||||
}
|
||||
arg = constructor.call(arg);
|
||||
}
|
||||
argMap.put(parameter, arg);
|
||||
}
|
||||
|
|
|
@ -28,6 +28,8 @@ import reactor.core.publisher.Mono
|
|||
import reactor.test.StepVerifier
|
||||
import kotlin.coroutines.Continuation
|
||||
import kotlin.coroutines.coroutineContext
|
||||
import kotlin.reflect.full.primaryConstructor
|
||||
import kotlin.reflect.jvm.isAccessible
|
||||
|
||||
/**
|
||||
* Kotlin tests for [CoroutinesUtils].
|
||||
|
@ -206,6 +208,15 @@ class CoroutinesUtilsTests {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun invokeSuspendingFunctionWithValueClassWithPrivateConstructorParameter() {
|
||||
val method = CoroutinesUtilsTests::class.java.declaredMethods.first { it.name.startsWith("suspendingFunctionWithValueClassWithPrivateConstructor") }
|
||||
val mono = CoroutinesUtils.invokeSuspendingFunction(method, this, "foo", null) as Mono
|
||||
runBlocking {
|
||||
Assertions.assertThat(mono.awaitSingleOrNull()).isEqualTo("foo")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun invokeSuspendingFunctionWithExtension() {
|
||||
val method = CoroutinesUtilsTests::class.java.getDeclaredMethod("suspendingFunctionWithExtension",
|
||||
|
@ -293,6 +304,11 @@ class CoroutinesUtilsTests {
|
|||
return value?.value
|
||||
}
|
||||
|
||||
suspend fun suspendingFunctionWithValueClassWithPrivateConstructor(value: ValueClassWithPrivateConstructor): String? {
|
||||
delay(1)
|
||||
return value.value
|
||||
}
|
||||
|
||||
suspend fun CustomException.suspendingFunctionWithExtension(): String {
|
||||
delay(1)
|
||||
return "${this.message}"
|
||||
|
@ -331,6 +347,13 @@ class CoroutinesUtilsTests {
|
|||
}
|
||||
}
|
||||
|
||||
@JvmInline
|
||||
value class ValueClassWithPrivateConstructor private constructor(val value: String) {
|
||||
companion object {
|
||||
fun from(value: String) = ValueClassWithPrivateConstructor(value)
|
||||
}
|
||||
}
|
||||
|
||||
class CustomException(message: String) : Throwable(message)
|
||||
|
||||
}
|
||||
|
|
|
@ -319,7 +319,11 @@ public class InvocableHandlerMethod extends HandlerMethod {
|
|||
KType type = parameter.getType();
|
||||
if (!(type.isMarkedNullable() && arg == null) && type.getClassifier() instanceof KClass<?> kClass
|
||||
&& KotlinDetector.isInlineClass(JvmClassMappingKt.getJavaClass(kClass))) {
|
||||
arg = KClasses.getPrimaryConstructor(kClass).call(arg);
|
||||
KFunction<?> constructor = KClasses.getPrimaryConstructor(kClass);
|
||||
if (!KCallablesJvm.isAccessible(constructor)) {
|
||||
KCallablesJvm.setAccessible(constructor, true);
|
||||
}
|
||||
arg = constructor.call(arg);
|
||||
}
|
||||
argMap.put(parameter, arg);
|
||||
}
|
||||
|
|
|
@ -112,6 +112,13 @@ class InvocableHandlerMethodKotlinTests {
|
|||
Assertions.assertThat(value).isNull()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun valueClassWithPrivateConstructor() {
|
||||
composite.addResolver(StubArgumentResolver(Char::class.java, 'a'))
|
||||
val value = getInvocable(ValueClassHandler::class.java, Char::class.java).invokeForRequest(request, null)
|
||||
Assertions.assertThat(value).isEqualTo('a')
|
||||
}
|
||||
|
||||
@Test
|
||||
fun propertyAccessor() {
|
||||
val value = getInvocable(PropertyAccessorHandler::class.java).invokeForRequest(request, null)
|
||||
|
@ -191,6 +198,8 @@ class InvocableHandlerMethodKotlinTests {
|
|||
fun valueClassWithNullable(limit: LongValueClass?) =
|
||||
limit?.value
|
||||
|
||||
fun valueClassWithPrivateConstructor(limit: ValueClassWithPrivateConstructor) =
|
||||
limit.value
|
||||
}
|
||||
|
||||
private class PropertyAccessorHandler {
|
||||
|
@ -238,6 +247,13 @@ class InvocableHandlerMethodKotlinTests {
|
|||
}
|
||||
}
|
||||
|
||||
@JvmInline
|
||||
value class ValueClassWithPrivateConstructor private constructor(val value: Char) {
|
||||
companion object {
|
||||
fun from(value: Char) = ValueClassWithPrivateConstructor(value)
|
||||
}
|
||||
}
|
||||
|
||||
class CustomException(message: String) : Throwable(message)
|
||||
|
||||
}
|
||||
|
|
|
@ -332,7 +332,11 @@ public class InvocableHandlerMethod extends HandlerMethod {
|
|||
KType type = parameter.getType();
|
||||
if (!(type.isMarkedNullable() && arg == null) && type.getClassifier() instanceof KClass<?> kClass
|
||||
&& KotlinDetector.isInlineClass(JvmClassMappingKt.getJavaClass(kClass))) {
|
||||
arg = KClasses.getPrimaryConstructor(kClass).call(arg);
|
||||
KFunction<?> constructor = KClasses.getPrimaryConstructor(kClass);
|
||||
if (!KCallablesJvm.isAccessible(constructor)) {
|
||||
KCallablesJvm.setAccessible(constructor, true);
|
||||
}
|
||||
arg = constructor.call(arg);
|
||||
}
|
||||
argMap.put(parameter, arg);
|
||||
}
|
||||
|
|
|
@ -222,6 +222,14 @@ class InvocableHandlerMethodKotlinTests {
|
|||
assertHandlerResultValue(result, "null")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun valueClassWithPrivateConstructor() {
|
||||
this.resolvers.add(stubResolver(1L, Long::class.java))
|
||||
val method = ValueClassController::valueClassWithPrivateConstructor.javaMethod!!
|
||||
val result = invoke(ValueClassController(), method, 1L)
|
||||
assertHandlerResultValue(result, "1")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun propertyAccessor() {
|
||||
this.resolvers.add(stubResolver(null, String::class.java))
|
||||
|
@ -368,6 +376,8 @@ class InvocableHandlerMethodKotlinTests {
|
|||
fun valueClassWithNullable(limit: LongValueClass?) =
|
||||
"${limit?.value}"
|
||||
|
||||
fun valueClassWithPrivateConstructor(limit: ValueClassWithPrivateConstructor) =
|
||||
"${limit.value}"
|
||||
}
|
||||
|
||||
class PropertyAccessorController {
|
||||
|
@ -416,5 +426,12 @@ class InvocableHandlerMethodKotlinTests {
|
|||
}
|
||||
}
|
||||
|
||||
@JvmInline
|
||||
value class ValueClassWithPrivateConstructor private constructor(val value: Long) {
|
||||
companion object {
|
||||
fun from(value: Long) = ValueClassWithPrivateConstructor(value)
|
||||
}
|
||||
}
|
||||
|
||||
class CustomException(message: String) : Throwable(message)
|
||||
}
|
Loading…
Reference in New Issue