Runtime Hints for Spring Boot 3 AOT with jOOQ 3.18+

338 Views Asked by At

Starting a native Spring Boot image with an application that uses jOOQ 3.18+ results in

Caused by: java.lang.NullPointerException: null
        at org.jooq.impl.DefaultBinding.binding(DefaultBinding.java:487)
        at org.jooq.impl.DefaultBinding.binding(DefaultBinding.java:329)
        at org.jooq.impl.DefaultDataType.<init>(DefaultDataType.java:391)
        at org.jooq.impl.DefaultDataType.<init>(DefaultDataType.java:335)
        at org.jooq.impl.DefaultDataType.<init>(DefaultDataType.java:331)
        at org.jooq.impl.DefaultDataType.<init>(DefaultDataType.java:319)
        at org.jooq.impl.ArrayDataType.<init>(ArrayDataType.java:63)
        at org.jooq.impl.AbstractDataType.getArrayDataType(AbstractDataType.java:660)
        at org.jooq.impl.DefaultDataType.getArrayDataType(DefaultDataType.java:136)
        at org.jooq.impl.DefaultDataType.<init>(DefaultDataType.java:396)
        at org.jooq.impl.DefaultDataType.<init>(DefaultDataType.java:335)
        at org.jooq.impl.DefaultDataType.<init>(DefaultDataType.java:331)
        at org.jooq.impl.DefaultDataType.<init>(DefaultDataType.java:315)
        at org.jooq.impl.BuiltInDataType.<init>(BuiltInDataType.java:60)
        at org.jooq.impl.SQLDataType.<clinit>(SQLDataType.java:621)
        ... 86 common frames omitted

After investigation, the reflect-config.json from Spring Boot 3 misses an entry for java.time.Year which is used in org.jooq.impl.SQLDataType.java on line 621 (which matches the trace) as:

...
    public static final DataType<Year> YEAR = new BuiltInDataType<>(Year.class, "year");
...

This was added in jOOQ for supporting a MySQL type.

To have this type available in the built native image, I have tried to add a hint to the compiler based on the docs. I import the following hints on one of my @Configurations:

class JooqRuntimeHints : RuntimeHintsRegistrar {
    override fun registerHints(hints: RuntimeHints, @Nullable classLoader: ClassLoader?) {
        // Register classes
        hints.reflection().registerType(java.time.Year::class.java)
        hints.reflection().registerField(ReflectionUtils.findField(SQLDataType::class.java, "YEAR")!!)
        println("Finished adding runtime hints for jOOQ")
    }
}

However, the error doesn't change despite adding this. I even see "Finished adding runtime hints for jOOQ" in the build logs, so the hint is definitely applied.

Any clue on how to add the proper hint?

0

There are 0 best solutions below