diff --git a/src/main/resources/META-INF/native-image/io.floci/floci-cli/reflect-config.json b/src/main/resources/META-INF/native-image/io.floci/floci-cli/reflect-config.json index 0eb2d5a..aeb7718 100644 --- a/src/main/resources/META-INF/native-image/io.floci/floci-cli/reflect-config.json +++ b/src/main/resources/META-INF/native-image/io.floci/floci-cli/reflect-config.json @@ -11,6 +11,12 @@ "allDeclaredMethods": true, "allDeclaredConstructors": true }, + { + "name": "io.floci.cli.update.UpdateCache", + "allDeclaredFields": true, + "allDeclaredMethods": true, + "allDeclaredConstructors": true + }, { "name": "com.fasterxml.jackson.databind.ser.std.ToStringSerializer", "allDeclaredMethods": true diff --git a/src/test/java/io/floci/cli/unit/ReflectConfigTest.java b/src/test/java/io/floci/cli/unit/ReflectConfigTest.java new file mode 100644 index 0000000..0d2b253 --- /dev/null +++ b/src/test/java/io/floci/cli/unit/ReflectConfigTest.java @@ -0,0 +1,49 @@ +package io.floci.cli.unit; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import io.floci.cli.config.GlobalConfigStore; +import io.floci.cli.config.Profile; +import io.floci.cli.update.UpdateCache; +import org.junit.jupiter.api.Test; + +import java.io.InputStream; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static org.junit.jupiter.api.Assertions.*; + +/** + * The JVM has full reflection, so a type Jackson binds by field name works in every unit test and + * fails only in the native binary when it is missing here (BL-025: the update cache was written + * empty). Every such type must stay registered. + */ +class ReflectConfigTest { + + private static final List> JACKSON_BOUND = List.of( + Profile.class, GlobalConfigStore.GlobalConfig.class, UpdateCache.class); + + // Jackson reads the fields, calls the accessors and the constructor of each bound type. + private static final List REQUIRED_FLAGS = + List.of("allDeclaredFields", "allDeclaredMethods", "allDeclaredConstructors"); + + @Test + void everyJacksonBoundTypeIsRegisteredForNativeReflection() throws Exception { + Map registered = new HashMap<>(); + try (InputStream in = getClass().getResourceAsStream( + "/META-INF/native-image/io.floci/floci-cli/reflect-config.json")) { + assertNotNull(in, "reflect-config.json is on the classpath"); + for (JsonNode entry : new ObjectMapper().readTree(in)) { + registered.put(entry.path("name").asText(), entry); + } + } + for (Class type : JACKSON_BOUND) { + JsonNode entry = registered.get(type.getName()); + assertNotNull(entry, type.getName() + " is missing from reflect-config.json"); + for (String flag : REQUIRED_FLAGS) { + assertTrue(entry.path(flag).asBoolean(false), type.getName() + " needs \"" + flag + "\": true"); + } + } + } +}