Remove unnecessary method.isAccessible() invocation
Closes gh-32548
This commit is contained in:
parent
dc982d0d51
commit
cf87441a26
|
@ -115,7 +115,7 @@ public abstract class CoroutinesUtils {
|
|||
Assert.isTrue(KotlinDetector.isSuspendingFunction(method), "Method must be a suspending function");
|
||||
KFunction<?> function = ReflectJvmMapping.getKotlinFunction(method);
|
||||
Assert.notNull(function, () -> "Failed to get Kotlin function for method: " + method);
|
||||
if (method.isAccessible() && !KCallablesJvm.isAccessible(function)) {
|
||||
if (!KCallablesJvm.isAccessible(function)) {
|
||||
KCallablesJvm.setAccessible(function, true);
|
||||
}
|
||||
Mono<Object> mono = MonoKt.mono(context, (scope, continuation) -> {
|
||||
|
|
|
@ -93,6 +93,17 @@ class CoroutinesUtilsTests {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun invokePrivateSuspendingFunction() {
|
||||
val method = CoroutinesUtilsTests::class.java.getDeclaredMethod("privateSuspendingFunction", String::class.java, Continuation::class.java)
|
||||
val publisher = CoroutinesUtils.invokeSuspendingFunction(method, this, "foo")
|
||||
Assertions.assertThat(publisher).isInstanceOf(Mono::class.java)
|
||||
StepVerifier.create(publisher)
|
||||
.expectNext("foo")
|
||||
.expectComplete()
|
||||
.verify()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun invokeNonSuspendingFunction() {
|
||||
val method = CoroutinesUtilsTests::class.java.getDeclaredMethod("nonSuspendingFunction", String::class.java)
|
||||
|
@ -252,6 +263,11 @@ class CoroutinesUtilsTests {
|
|||
return value
|
||||
}
|
||||
|
||||
private suspend fun privateSuspendingFunction(value: String): String {
|
||||
delay(1)
|
||||
return value
|
||||
}
|
||||
|
||||
suspend fun suspendingFunctionWithNullable(value: String?): String? {
|
||||
delay(1)
|
||||
return value
|
||||
|
|
|
@ -305,7 +305,7 @@ public class InvocableHandlerMethod extends HandlerMethod {
|
|||
if (function == null) {
|
||||
return method.invoke(target, args);
|
||||
}
|
||||
if (method.isAccessible() && !KCallablesJvm.isAccessible(function)) {
|
||||
if (!KCallablesJvm.isAccessible(function)) {
|
||||
KCallablesJvm.setAccessible(function, true);
|
||||
}
|
||||
Map<KParameter, Object> argMap = CollectionUtils.newHashMap(args.length + 1);
|
||||
|
|
|
@ -84,6 +84,15 @@ class InvocableHandlerMethodKotlinTests {
|
|||
Assertions.assertThat(value).isNull()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun private() {
|
||||
composite.addResolver(StubArgumentResolver(Float::class.java, 1.2f))
|
||||
val value = getInvocable(Handler::class.java, Float::class.java).invokeForRequest(request, null)
|
||||
|
||||
Assertions.assertThat(getStubResolver(0).resolvedParameters).hasSize(1)
|
||||
Assertions.assertThat(value).isEqualTo("1.2")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun valueClass() {
|
||||
composite.addResolver(StubArgumentResolver(Long::class.java, 1L))
|
||||
|
@ -182,6 +191,8 @@ class InvocableHandlerMethodKotlinTests {
|
|||
return null
|
||||
}
|
||||
|
||||
private fun private(value: Float) = value.toString()
|
||||
|
||||
}
|
||||
|
||||
private class ValueClassHandler {
|
||||
|
|
|
@ -318,7 +318,7 @@ public class InvocableHandlerMethod extends HandlerMethod {
|
|||
if (function == null) {
|
||||
return method.invoke(target, args);
|
||||
}
|
||||
if (method.isAccessible() && !KCallablesJvm.isAccessible(function)) {
|
||||
if (!KCallablesJvm.isAccessible(function)) {
|
||||
KCallablesJvm.setAccessible(function, true);
|
||||
}
|
||||
Map<KParameter, Object> argMap = CollectionUtils.newHashMap(args.length + 1);
|
||||
|
|
|
@ -112,11 +112,18 @@ class InvocableHandlerMethodKotlinTests {
|
|||
@Test
|
||||
fun privateController() {
|
||||
this.resolvers.add(stubResolver("foo"))
|
||||
val method = PrivateCoroutinesController::singleArg.javaMethod!!
|
||||
val result = invoke(PrivateCoroutinesController(), method,"foo")
|
||||
val method = PrivateController::singleArg.javaMethod!!
|
||||
val result = invoke(PrivateController(), method,"foo")
|
||||
assertHandlerResultValue(result, "success:foo")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun privateFunction() {
|
||||
val method = PrivateController::class.java.getDeclaredMethod("private")
|
||||
val result = invoke(PrivateController(), method)
|
||||
assertHandlerResultValue(result, "private")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun defaultValue() {
|
||||
this.resolvers.add(stubResolver(null, String::class.java))
|
||||
|
@ -330,12 +337,14 @@ class InvocableHandlerMethodKotlinTests {
|
|||
}
|
||||
}
|
||||
|
||||
private class PrivateCoroutinesController {
|
||||
private class PrivateController {
|
||||
|
||||
suspend fun singleArg(q: String?): String {
|
||||
delay(1)
|
||||
return "success:$q"
|
||||
}
|
||||
|
||||
private fun private() = "private"
|
||||
}
|
||||
|
||||
class DefaultValueController {
|
||||
|
|
Loading…
Reference in New Issue