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

BindingReflectionHintsRegistrar do not take into account the boxed type Boolean #33380

Closed
czp3009 opened this issue Aug 13, 2024 · 2 comments
Closed
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) theme: aot An issue related to Ahead-of-time processing theme: kotlin An issue related to Kotlin support type: bug A general bug
Milestone

Comments

@czp3009
Copy link

czp3009 commented Aug 13, 2024

spring version: 6.1.8

example:

data class Nullable(
    val isX: Boolean?
)

@SpringBootApplication
@RestController
class Application {
    @GetMapping("/")
    fun nullable() = Nullable(true)
}

response:

{"timestamp":"2024-08-13T15:14:13.916+00:00","status":500,"error":"Internal Server Error","path":"/"}

stack trace:

org.graalvm.nativeimage.MissingReflectionRegistrationError: The program tried to reflectively invoke method public final java.lang.Boolean org.example.springnativeimageboxedtypeissuereproduction.Nullable.isX() 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.10/java.lang.reflect.Method.acquireMethodAccessor(Method.java:77) ~[spring-native-image-boxed-type-issue-reproduction:na]
        at java.base@17.0.10/java.lang.reflect.Method.invoke(Method.java:566) ~[spring-native-image-boxed-type-issue-reproduction:na]
        at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:688) ~[spring-native-image-boxed-type-issue-reproduction:2.17.2]
        at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:770) ~[spring-native-image-boxed-type-issue-reproduction:2.17.2]
        at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:183) ~[na:na]
        at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider._serialize(DefaultSerializerProvider.java:502) ~[spring-native-image-boxed-type-issue-reproduction:2.17.2]
        at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:341) ~[spring-native-image-boxed-type-issue-reproduction:2.17.2]
        at com.fasterxml.jackson.databind.ObjectWriter$Prefetch.serialize(ObjectWriter.java:1574) ~[na:na]
        at com.fasterxml.jackson.databind.ObjectWriter.writeValue(ObjectWriter.java:1061) ~[spring-native-image-boxed-type-issue-reproduction:2.17.2]

issue reproduction repository: https://github.com/czp3009/spring-native-image-boxed-type-issue-reproduction

Possible causes:
The class BindingReflectionHintsRegistrar not consider the java boxed type 'Boolean' but kotlin nullable type will compiled into boxed type

(methodName.startsWith("is") && method.getParameterCount() == 0 && method.getReturnType() == boolean.class)) {

the code simply inference the java primitive type 'boolean''

if a method name starts with 'is' and return type is 'Boolean', the method will not be registered to native hint

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Aug 13, 2024
@jhoeller jhoeller added the in: core Issues in core modules (aop, beans, core, context, expression) label Aug 13, 2024
@sdeleuze sdeleuze self-assigned this Aug 13, 2024
@sdeleuze sdeleuze added theme: kotlin An issue related to Kotlin support theme: aot An issue related to Ahead-of-time processing and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Aug 13, 2024
@sdeleuze sdeleuze added this to the 6.1.x milestone Aug 13, 2024
@sdeleuze sdeleuze changed the title BindingReflectionHintsRegistrar not take into account the boxed type ‘Boolean’ BindingReflectionHintsRegistrar do not take into account the boxed type Boolean Aug 13, 2024
@sdeleuze sdeleuze modified the milestones: 6.1.x, 6.1.13 Aug 13, 2024
@izeye
Copy link
Contributor

izeye commented Oct 20, 2024

This seems to be a bug but hasn't been labeled accordingly, so this seems to be missing in the release notes.

@bclozel bclozel added the type: bug A general bug label Oct 20, 2024
@bclozel
Copy link
Member

bclozel commented Oct 20, 2024

Thanks @izeye I've updated the release notes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) theme: aot An issue related to Ahead-of-time processing theme: kotlin An issue related to Kotlin support type: bug A general bug
Projects
None yet
Development

No branches or pull requests

6 participants