Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spring native not support method handler with kotlin default value #33384

Closed
czp3009 opened this issue Aug 14, 2024 · 0 comments
Closed

spring native not support method handler with kotlin default value #33384

czp3009 opened this issue Aug 14, 2024 · 0 comments
Assignees
Labels
theme: aot An issue related to Ahead-of-time processing theme: kotlin An issue related to Kotlin support type: enhancement A general enhancement
Milestone

Comments

@czp3009
Copy link

czp3009 commented Aug 14, 2024

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

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Aug 14, 2024
@sdeleuze sdeleuze self-assigned this Aug 14, 2024
@sdeleuze sdeleuze added in: web Issues in web modules (web, webmvc, webflux, websocket) theme: kotlin An issue related to Kotlin support type: enhancement A general enhancement theme: aot An issue related to Ahead-of-time processing and removed in: web Issues in web modules (web, webmvc, webflux, websocket) status: waiting-for-triage An issue we've not yet triaged or decided on labels Aug 14, 2024
@sdeleuze sdeleuze added this to the 6.1.13 milestone Aug 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme: aot An issue related to Ahead-of-time processing theme: kotlin An issue related to Kotlin support type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

3 participants