HelloController
method private fun formatBody
is not added to native compilation causing the error bellow when the /hello
endpoint is called.
2022-12-20T20:55:22.944+01:00 ERROR 34458 --- [ctor-http-nio-2] a.w.r.e.AbstractErrorWebExceptionHandler : [c7913109-1] 500 Server Error for HTTP GET "/hello/123"
kotlin.reflect.jvm.internal.KotlinReflectionInternalError: Could not compute caller for function: private open fun formatBody(value: kotlin.String): com.example.kotlin.HelloController.ResponseMessage defined in com.example.kotlin.HelloController[DeserializedSimpleFunctionDescriptor@253b4bd1] (member = null)
at kotlin.reflect.jvm.internal.KFunctionImpl$caller$2.invoke(KFunctionImpl.kt:88) ~[na:na]
Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException:
Error has been observed at the following site(s):
*__checkpoint ⇢ HTTP GET "/hello/123" [ExceptionHandlingWebHandler]
Original Stack Trace:
at kotlin.reflect.jvm.internal.KFunctionImpl$caller$2.invoke(KFunctionImpl.kt:88) ~[na:na]
at kotlin.reflect.jvm.internal.KFunctionImpl$caller$2.invoke(KFunctionImpl.kt:61) ~[na:na]
at kotlin.reflect.jvm.internal.ReflectProperties$LazyVal.invoke(ReflectProperties.java:63) ~[na:na]
at kotlin.reflect.jvm.internal.ReflectProperties$Val.getValue(ReflectProperties.java:32) ~[springboot-kotlin-native:1.7.21-release-272(1.7.21)]
Registering all methods in the controller fixes it (private methods in other classes are fine)
hints.reflection()
.registerType(HelloController::class.java, MemberCategory.INVOKE_DECLARED_METHODS)
Comment From: sbrannen
Can you please provide the source code for HelloController
?
Comment From: abelsromero
reproducer https://github.com/abelsromero/springboot-kotlin-native 🙇
You can see the /hello/{username}
endpoint just calls a silly format method to preffix the text. Doing some reflection exploring I saw the method is not returned as a Method
but insted is some Kotlin internal instance of type KCallable...which does not clarify to me why INVOKE_DECLARED_METHODS
works 🤔
Comment From: sdeleuze
Fixed by #29663.