spring version: 6.1.8
example:
@RestController
class DefaultController {
@GetMapping("/defaultValue")
fun defaultValue(@RequestParam(required = false) argument: Boolean? = null) = argument
}
test:
curl localhost:8080/defaultValue
{"timestamp":"2024-08-14T03:59:59.186+00:00","status":500,"error":"Internal Server Error","path":"/defaultValue"}
stack trace:
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Handler dispatch failed: org.graalvm.nativeimage.MissingReflectionRegistrationError: The program tried to reflectively invoke method public static java.lang.Boolean com.example.DefaultController.defaultValue$default(com.example.DefaultController,java.lang.Boolean,int,java.lang.Object) without it being registered for runtime reflection. Add it to the reflection metadata to solve this problem. See https://www.graalvm.org/latest/reference-manual/native-image/metadata/#reflection for help.] with root cause
org.graalvm.nativeimage.MissingReflectionRegistrationError: The program tried to reflectively invoke method public static java.lang.Boolean com.example.DefaultController.defaultValue$default(com.example.DefaultController,java.lang.Boolean,int,java.lang.Object) without it being registered for runtime reflection. Add it to the reflection metadata to solve this problem. See https://www.graalvm.org/latest/reference-manual/native-image/metadata/#reflection for help.
at org.graalvm.nativeimage.builder/com.oracle.svm.core.reflect.MissingReflectionRegistrationUtils.forQueriedOnlyExecutable(MissingReflectionRegistrationUtils.java:97) ~[na:na]
at java.base@17.0.11/java.lang.reflect.Method.acquireMethodAccessor(Method.java:77) ~[com.example.ApplicationKt:na]
at java.base@17.0.11/java.lang.reflect.Method.invoke(Method.java:566) ~[com.example.ApplicationKt:na]
at kotlin.reflect.jvm.internal.calls.CallerImpl$Method.callMethod(CallerImpl.kt:97) ~[com.example.ApplicationKt:1.9.24-release-822]
at kotlin.reflect.jvm.internal.calls.CallerImpl$Method$Static.call(CallerImpl.kt:106) ~[na:na]
at kotlin.reflect.jvm.internal.KCallableImpl.callDefaultMethod$kotlin_reflection(KCallableImpl.kt:215) ~[com.example.ApplicationKt:1.9.24-release-822]
at kotlin.reflect.jvm.internal.KCallableImpl.callBy(KCallableImpl.kt:112) ~[com.example.ApplicationKt:1.9.24-release-822]
at org.springframework.web.method.support.InvocableHandlerMethod$KotlinDelegate.invokeFunction(InvocableHandlerMethod.java:334) ~[na:na]
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:252) ~[com.example.ApplicationKt:6.1.11]
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:188) ~[com.example.ApplicationKt:6.1.11]
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:118) ~[com.example.ApplicationKt:6.1.11]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:926) ~[com.example.ApplicationKt:6.1.11]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:831) ~[com.example.ApplicationKt:6.1.11]
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) ~[com.example.ApplicationKt:6.1.11]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1089) ~[com.example.ApplicationKt:6.1.11]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:979) ~[com.example.ApplicationKt:6.1.11]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1014) ~[com.example.ApplicationKt:6.1.11]
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:903) ~[com.example.ApplicationKt:6.1.11]
issue reproduce repository: https://github.com/czp3009/spring-native-not-support-method-handler-with-kotlin-default-value
Possible causes: i notice that in this issue spring finally support kotlin default value in method handler
but according to code in PR, it seems that the native hint for method handlers with method names ending in '$default' is missing