Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GraalVM and Kotlin inline value classes?

I would like to use value class in native image:

@JvmInline
value class MyValueClass(val id: UUID)

I marked it for reflection:

@Configuration(proxyBeanMethods = false)
@RegisterReflectionForBinding(MyValueClass::class, ...)
class BeanConfiguration {

However, when running the image I get:

org.graalvm.nativeimage.MissingReflectionRegistrationError: The program tried to reflectively invoke method public final java.util.UUID com.example.MyValueClass.unbox-impl() 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]

How I can use inline value classes with GraalVM?

like image 965
pixel Avatar asked Dec 11 '25 11:12

pixel


1 Answers

I got it to work in spring boot 3.3 with the following hints (my value class is TimestampMicros). This makes all members available for reflection, including members generated by the kotlin compiler. It may be possible to fine-tune the included member categories, but I haven't tried:

@SpringBootApplication
@ImportRuntimeHints(PollingApplication.Hints::class)
class PollingApplication {
    class Hints : RuntimeHintsRegistrar {
        override fun registerHints(hints: RuntimeHints, classLoader: ClassLoader?) {
            hints.reflection().registerTypeIfPresent(classLoader, TimestampMicros::class.java.name) {
                it.withMembers(*MemberCategory.entries.toTypedArray())
            }
        }
    }
}
like image 84
Rogério Gatto Avatar answered Dec 13 '25 01:12

Rogério Gatto



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!