Skip to content

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

Closed
@czp3009

Description

@czp3009

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 [email protected]/java.lang.reflect.Method.acquireMethodAccessor(Method.java:77) ~[spring-native-image-boxed-type-issue-reproduction:na]
        at [email protected]/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

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)theme: aotAn issue related to Ahead-of-time processingtheme: kotlinAn issue related to Kotlin supporttype: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions