Skip to content

Write native configuration file when only lambda hints are present - #36989

Closed
junhyeong9812 wants to merge 1 commit into
spring-projects:mainfrom
junhyeong9812:fix/nativeconfig-lambda-hints
Closed

junhyeong9812 wants to merge 1 commit into
spring-projects:mainfrom
junhyeong9812:fix/nativeconfig-lambda-hints

Conversation

@junhyeong9812

Copy link
Copy Markdown
Contributor

Overview

FileNativeConfigurationWriter fails to write reachability-metadata.json when a RuntimeHints instance contains only lambda hints, silently dropping the lambda metadata.

Problem

NativeConfigurationWriter.write(RuntimeHints) only writes the configuration file when hasAnyHint(hints) returns true:

public void write(RuntimeHints hints) {
	if (hasAnyHint(hints)) {
		writeTo("reachability-metadata.json",
				writer -> new RuntimeHintsWriter().write(writer, hints));
	}
}

However hasAnyHint(hints) does not check ReflectionHints.lambdaHints():

private boolean hasAnyHint(RuntimeHints hints) {
	return (hints.proxies().jdkProxyHints().findAny().isPresent() ||
			hints.reflection().typeHints().findAny().isPresent() ||
			hints.resources().resourcePatternHints().findAny().isPresent() ||
			hints.resources().resourceBundleHints().findAny().isPresent() ||
			hints.jni().typeHints().findAny().isPresent() ||
			hasAnyDeprecatedHint(hints));
}

RuntimeHintsWriter already serializes lambda hints (see the oneLambda test in RuntimeHintsWriterTests), so when a RuntimeHints holds only lambda hints registered via ReflectionHints.registerLambda(...), hasAnyHint returns false, the file is never written, and the lambda metadata is lost. This is not caught on the JVM; it only surfaces as a native-image runtime failure.

Fix

Include lambda hints in hasAnyHint() so the configuration file is written whenever lambda hints are present:

hints.reflection().lambdaHints().findAny().isPresent() ||

Adds a lambdaConfig() test that registers only a lambda hint and asserts the file is written with the expected JSON. Without the fix the test fails with NoSuchFileException because no file is produced.

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.

Include lambda hints in hasAnyHint() so the configuration file is written
whenever lambda hints are present.

Signed-off-by: junhyeong9812 <pickjog@gmail.com>
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Jul 1, 2026
@sbrannen sbrannen self-assigned this Jul 2, 2026
@sbrannen sbrannen added in: core Issues in core modules (aop, beans, core, context, expression) theme: aot An issue related to Ahead-of-time processing type: bug A general bug and removed theme: aot An issue related to Ahead-of-time processing status: waiting-for-triage An issue we've not yet triaged or decided on labels Jul 2, 2026
@sbrannen sbrannen added this to the 7.0.9 milestone Jul 2, 2026
@sbrannen

sbrannen commented Jul 2, 2026

Copy link
Copy Markdown
Member

Good catch! 👍

This is effectively a bug that was introduced when the support for lambda hints was added in 7.0.6.

@sbrannen sbrannen closed this in d1470bb Jul 2, 2026
@junhyeong9812

Copy link
Copy Markdown
Contributor Author

Thank you for the review and merge, @sbrannen. Thanks to your work, I get to use a great framework every day. I really appreciate it.

@sbrannen

sbrannen commented Jul 4, 2026

Copy link
Copy Markdown
Member

@junhyeong9812, you're very welcome, and thanks for the kinds words!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

in: core Issues in core modules (aop, beans, core, context, expression) theme: aot An issue related to Ahead-of-time processing type: bug A general bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants