Register native configuration file when only lambda hints are present

Prior to this commit, FileNativeConfigurationWriter did not write reachability-metadata.json
when a RuntimeHints instance contained only lambda hints, because
NativeConfigurationWriter.hasAnyHint() omitted
ReflectionHints.lambdaHints() from its checks. As a result, lambda
metadata emitted by RuntimeHintsWriter was silently dropped.

This commit addresses that by including lambda hints in hasAnyHint() so
the configuration file is written whenever lambda hints are present.

Closes gh-36989

Signed-off-by: junhyeong9812 <pickjog@gmail.com>
This commit is contained in:
junhyeong9812
2026-07-02 12:06:24 +02:00
committed by Sam Brannen
parent 347f23a73f
commit d1470bbb25
2 changed files with 30 additions and 0 deletions
@@ -46,6 +46,7 @@ public abstract class NativeConfigurationWriter {
private boolean hasAnyHint(RuntimeHints hints) {
return (hints.proxies().jdkProxyHints().findAny().isPresent() ||
hints.reflection().typeHints().findAny().isPresent() ||
hints.reflection().lambdaHints().findAny().isPresent() ||
hints.resources().resourcePatternHints().findAny().isPresent() ||
hints.resources().resourceBundleHints().findAny().isPresent() ||
hints.jni().typeHints().findAny().isPresent() ||
@@ -23,6 +23,7 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
@@ -137,6 +138,34 @@ class FileNativeConfigurationWriterTests {
""");
}
@Test // gh-36989
void lambdaConfig() throws Exception {
FileNativeConfigurationWriter generator = new FileNativeConfigurationWriter(tempDir);
RuntimeHints hints = new RuntimeHints();
hints.reflection().registerLambda(Integer.class, builder -> builder
.withDeclaringMethod("getCell", Integer.class, Integer.class)
.withInterfaces(Supplier.class));
generator.write(hints);
assertEquals("""
{
"reflection": [
{
"type": {
"lambda": {
"declaringClass": "java.lang.Integer",
"declaringMethod": {
"name": "getCell",
"parameterTypes": [ "java.lang.Integer", "java.lang.Integer" ]
},
"interfaces": [ "java.util.function.Supplier" ]
}
}
}
]
}
""");
}
@Test
void jniConfig() throws Exception {
// same format as reflection so just test basic file generation