Skip to content

Start Grails as a native image without recorded metadata, checked by an end-to-end i18n module - #16180

Merged
codeconsole merged 64 commits into
apache:9.0.xfrom
codeconsole:feature/native-i18n-verification-8.0.x
Oct 29, 2026
Merged

codeconsole merged 64 commits into
apache:9.0.xfrom
codeconsole:feature/native-i18n-verification-8.0.x

Conversation

@codeconsole

@codeconsole codeconsole commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

per request of @borinquenkid

Adds the end-to-end module #16176 asks for: an application that resolves messages from each way a bundle reaches the message source. It also makes the framework changes that let that application run as a GraalVM native image with no recorded metadata.

What it checks

Bundle Base name Why
the application's own messages The case Spring Boot's own hints already cover, as a control.
the plugin's native-messages Namespaced, so Boot's two hardcoded messages* patterns never reach it. The plugin name is multi-word, so it also covers the descriptor's hyphenated spelling being matched against the plugin's camel-case one.
one the application configured config.i18n.custom Outside grails-app/i18n, dotted, so it proves the base name is converted to config/i18n/custom before use.

Each is resolved in English and in a locale variant. An unknown code is resolved too, under use-code-as-default-message, because base names alone would not prove MessageSourceProperties was bound — the whole object binds at once or not at all. The application also reads a value from the plugin's plugin.yml, which an image could not find before this change.

Native image without recorded metadata

Now that #16165 has merged, 9.0.x compiles the framework and its plugins with invokedynamic on Groovy 6.0.0, so every remaining gap was in the framework itself. The image is built only from what the framework registers while the code is generated, plus the hints derived from the configured base names. No agent-traced metadata is checked in or generated, so a native failure points at the framework, not at this fixture.

The framework changes, each in its own commit with tests:

  • No dynamic dispatch before anything can register for it. The Application class's static initializer records the main class with a direct System.setProperty call. Settings and MultiTenancySettings are compiled statically. The default stack trace filterer is created directly instead of reflectively.
  • Plugins. Registered: the plugin descriptors, the plugin classes they name, and those classes' class files; the classes named in META-INF/grails.factories; and the beans plugins declare through a BeanRegistrar or the bean DSL, which are created and wired reflectively at startup.
  • Plugin configuration. A plugin's plugin.yml is found relative to its class root, and an image has none, so every plugin looked for the same /plugin.yml. Each plugin's configuration is now copied under its plugin class's name while the code is generated, and PluginUtils.readPluginConfiguration prefers that copy.
  • Artefacts. Registered: the GrailsClass each handler creates, read through the new ArtefactHandlerAdapter.getGrailsClassImpl(), and every artefact, including the default URL mappings and the ones plugins provide.
  • What compiled Groovy does reflectively, read from the bytecode of the framework's packages and of the application's: Groovy enum constructors, JDK proxies for the interfaces closures and maps are coerced to wherever the code names the interface (a closure statically compiled code passes or assigns to one, or any as with a class literal, whatever the value is declared as), trait helpers, members Spring injects through annotations, and the setProperty lookup on every Groovy class.
  • Dynamically compiled descriptors and the bean DSL. Registered: the framework's constants and static helpers they read, plus the JDK collection, string and number types they call through the metaclass.
  • Odds and ends. Registered: the property editors, the Caffeine cache classes GraalVM's own metadata misses, META-INF/grails.build.info (without it an image starts in development), the default validation messages bundle, the URL mappings builder, the servlet context holder, and the promise factories the event bus reads its executor from.

The deployment guide's AOT section has a new "What the framework registers for you" list.

Running it

The JVM half runs in check and needs nothing special. It starts the packaged application in production, the environment the image starts in, and again in development, the environment grails run-app starts in, where bundles stopped resolving until #16179. Each run, the image's included, is told which environment to expect and fails in any other.

cd end-to-end
./gradlew :native-i18n:check

The native half is opt-in and needs GraalVM 25 or later in GRAALVM_HOME and JAVA_HOME (on the 21 line nativeCompile fails on oracle/graal#10200):

./gradlew :native-i18n:check -PnativeTests

CI runs it at the end of the End to End job, on GraalVM Community 25.2, against the framework that job has already published.

Limitations

  • What the framework registers covers starting the application. What a request reaches is still recorded with traceNativeMetadata: the framework's own reflection along the request's path, and the application's own dynamically compiled code, including a closure such code passes to a method taking an interface. native-i18n starts the image and resolves its bundles; it serves no request.
  • The JVM half cannot falsify a resource hint. On a JVM every bundle on the classpath is readable whether it was registered or not. Its value is as a fixture guard that keeps the bundles and the assertions from drifting apart, and it has caught lifecycle bugs: it is what found BUGFIX: message bundles silently failing to resolve in development #16179.

Thanks to @matrei for running the native half and working out both upstream blockers.

@codecov

codecov Bot commented Aug 20, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.82090% with 57 lines in your changes missing coverage. Please review.
✅ Project coverage is 64.5532%. Comparing base (5175f69) to head (6f481ef).

Files with missing lines Patch % Lines
...g/apache/grails/core/aot/BytecodeRuntimeHints.java 88.3117% 11 Missing and 7 partials ⚠️
...flectionBeanFactoryInitializationAotProcessor.java 77.3585% 9 Missing and 3 partials ⚠️
...e/grails/core/aot/GrailsFactoriesRuntimeHints.java 71.8750% 6 Missing and 3 partials ⚠️
...flectionBeanFactoryInitializationAotProcessor.java 82.2222% 1 Missing and 7 partials ⚠️
...BytecodeBeanFactoryInitializationAotProcessor.java 75.8621% 6 Missing and 1 partial ⚠️
...vy/org/apache/grails/core/plugins/PluginUtils.java 84.6154% 1 Missing and 1 partial ⚠️
...ache/grails/core/aot/GrailsPluginRuntimeHints.java 90.9091% 0 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@                 Coverage Diff                 @@
##                9.0.x     #16180         +/-   ##
===================================================
+ Coverage     45.6019%   64.5532%   +18.9514%     
- Complexity        880      30314      +29434     
===================================================
  Files              89       2382       +2293     
  Lines            5059     117046     +111987     
  Branches          886      21389      +20503     
===================================================
+ Hits             2307      75557      +73250     
- Misses           2440      31840      +29400     
- Partials          312       9649       +9337     
Files with missing lines Coverage Δ
...core/src/main/groovy/grails/config/Settings.groovy 100.0000% <ø> (ø)
...ain/groovy/grails/core/ArtefactHandlerAdapter.java 58.6207% <100.0000%> (ø)
...rails/core/GrailsBootstrapRegistryInitializer.java 83.8710% <100.0000%> (ø)
...g/apache/grails/core/aot/CaffeineRuntimeHints.java 100.0000% <100.0000%> (ø)
.../apache/grails/core/aot/GrailsApiRuntimeHints.java 100.0000% <100.0000%> (ø)
...he/grails/core/aot/GrailsResourceRuntimeHints.java 100.0000% <100.0000%> (ø)
...pache/grails/core/aot/JdkDispatchRuntimeHints.java 100.0000% <100.0000%> (ø)
...gurationBeanFactoryInitializationAotProcessor.java 100.0000% <100.0000%> (ø)
...he/grails/core/aot/PropertyEditorRuntimeHints.java 100.0000% <100.0000%> (ø)
...compiler/injection/ApplicationClassInjector.groovy 59.2593% <100.0000%> (ø)
... and 13 more

... and 2270 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@codeconsole
codeconsole marked this pull request as ready for review September 2, 2026 03:19
@matrei

matrei commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

Review Findings

Head 2fb4179e56 on 8.0.x, merge base 43510784cf. #16179 has merged, so the diff is now only the end-to-end/ module (14 files, 477 additions). git merge-tree is clean.

CI on this head is green, including "End to End Tests (end-to-end build only)", which runs ./gradlew check in end-to-end and therefore the new i18nCheckOnJvm task.

I also ran the native half, which the PR says nobody has. Setup followed the README exactly: Oracle GraalVM for JDK 21 (21.0.12) as JAVA_HOME and GRAALVM_HOME, grails-gradle and the framework republished to build/local-maven with -PgrailsIndy=true (verified: 0 of 300 sampled grails-core classes carry a CallSiteArray, 168 contain invokedynamic), then ./gradlew :native-i18n:check -PnativeTests. The JVM half passed. The native half fails, twice over, for reasons that are upstream of this PR but that the PR's README presents as solved. Details in the first finding.

The PR is no longer marked draft, but the description still says "the reason this is a draft" and "the native half has not been executed yet". The second statement is accurate and should stay; the draft flag should come back until the first finding is resolved.

Findings

High: the native half cannot pass on 8.0.x as pinned, and the README recipe does not produce a working image

What happens when the README is followed:

Step GraalVM for JDK 21 (21.0.12) Oracle GraalVM 25.3.4 (native-image 25.0.4.1)
nativeCompile fails in 4s at "Initializing": Could not find target method: ... Target_org_codehaus_groovy_vmplugin_v7_IndyInterface_invalidateSwitchPoints.invalidateSwitchPoints() succeeds, 5m 34s, 157 MiB binary
i18nCheckOnNative not reached binary dies before Spring starts: BootstrapMethodError: NullPointerException at IndyInterface.makeBootHandle(IndyInterface.java:247) from Application.<clinit>

The first failure is GraalVM's bundled Groovy substitution targeting a method Groovy 4+ no longer has (oracle/graal #10200, #13096; fixed on master in April 2026 and present in the 25 line, not in 21). So the README's "a GraalVM JDK" has to say "GraalVM for JDK 25 or later", and the JDK-matching advice in the same section needs rewording, since the framework is then published on 21 and the image built on 25.

The second failure is the real blocker. Line 247 passes FROM_CACHE_HANDLE_METHOD, a static final handle that IndyInterface.<clinit> assigns, and it is null: the bootstrap method ran before its declaring class was initialised. This is not Grails-specific and not a metadata gap. I reproduced the identical exception with a ten-line Groovy hello-world, no Spring, no Grails, metadata from the tracing agent, against Groovy 5.1.2 and against Groovy 4.0.27. Registering every IndyInterface method for reflection changes nothing; --exact-reachability-metadata raises no missing-registration error; --initialize-at-build-time for the class fails the build on image-heap objects, as Groovy's own tracker says it will. The class-initialisation report confirms IndyInterface is RUN_TIME.

Groovy knows about it. IndyInterface.java in 6.0.0-RC-1 carries this comment above a new ensureInitialized() guard:

Guards against a GraalVM native-image gap: the runtime invokedynamic linkage invokes a bootstrap method without running its declaring class's <clinit> first (observed on GraalVM CE 25.2.4; on HotSpot the bootstrap's DirectMethodHandle carries a class-initialization barrier).

The same hello-world against 6.0.0-RC-1 fails at that guard with BUG! unreachable: LOOKUP read before initialization, so even the Groovy 6 workaround does not hold on Oracle GraalVM 25.3.4. The wider work is all on the Groovy 6 line: GROOVY-12234 "Indy: AOT link mode so dynamic Groovy dispatch works in GraalVM native images" (6.0.0-beta-2), GROOVY-12227, and in the unreleased 6.0.0-RC-2 GROOVY-12364, GROOVY-12365 (ship reachability metadata in the groovy jar) and GROOVY-12366 (ship native-image.properties). GROOVY-12234's description states the status plainly: before it, dynamic Groovy cannot run in an image at all, indy or not, and the only workaround was compiling everything non-indy with groovy-callsite.

Grails 8.0.x pins groovy.version 5.1.2 in dependencies.gradle. None of the above is in any 5.1.x release.

Consequences for this PR:

  • The README section "Native image verification" describes a recipe (GraalVM JDK, indy on both sides) as if following it yields an image that runs the check. It does not, on any released Groovy the BOM can use. The section should say what the actual precondition is (a Groovy 6 with the AOT link mode, and a GraalVM on which the class-init gap is closed) and that neither exists in a release today, so -PnativeTests is expected to fail until then. Otherwise the next person loses a day the way I nearly did.
  • The two build comments in native-i18n/build.gradle about 16 threads and six minutes, and the README's UnsupportedFeatureError: Tried to define class paragraph, are observations from some earlier build. Whichever toolchain and Groovy they came from should be named, because they are not reproducible with what 8.0.x pins.
  • "Released Grails artifacts are built without indy, so no released Grails can produce a working image" (README.md:103) is true but misleading in isolation: with Groovy 5 no build of Grails can, indy or not. The sentence should say so.
  • The claim in the description that this module lets a missing hint "actually be falsified" is not yet true. The JVM half is a fixture guard; the native half needs the Groovy 6 line before it can assert anything. That is fine for a first landing as long as the module and README say it, and #16176 is updated with the two upstream blockers.

What would make the native half useful sooner: the snapshot canary workflow already rebuilds Grails against a Groovy branch by rewriting groovy.version. Running this module in that job, on GraalVM 25, once GROOVY-12366 ships in RC-2, is the cheapest way to learn when the upstream gap closes. I did not attempt a Groovy 6 rebuild of the framework here; it is a different review.

Medium: the "bundle never registered" diagnostic can never fire under this configuration

References:

  • end-to-end/native-i18n/grails-app/conf/application.yml:27 sets use-code-as-default-message: true
  • end-to-end/native-i18n/grails-app/init/nativei18n/Application.groovy:96-99 catches an exception from getMessage and reports "its bundle was never registered"
  • end-to-end/README.md:60 and the class Javadoc say a missing hint shows up "as a NoSuchMessageException"

With useCodeAsDefaultMessage on, AbstractMessageSource.getMessage(code, args, locale) returns the code itself instead of throwing, so a bundle that is missing from the image produces actual == code, and the failure surfaces through the other branch as 'native.plugin.greeting' for fr resolved to 'native.plugin.greeting', expected '...'. The check still fails, so this is not a false pass, but the catch block is dead code, its message is the one a reader would want, and the README and Javadoc describe an exception that this application is configured never to see.

Suggested fix: keep the property (the unknown-code assertion needs it), but make check treat actual == code as "bundle not registered" and say so, and drop or reword the NoSuchMessageException sentence in the README and the Javadoc.

Low: leftover debugging in the build script

Reference: end-to-end/native-i18n/build.gradle:28-31

// Applied the legacy way: the Spring Boot plugin is on this build's classpath through the
// Grails plugin, so the id resolves, but it carries no version for the plugins block.
// TEMP probe: disabled
//apply plugin: 'org.springframework.boot.aot'

Should go. It is also unnecessary: Spring Boot's Gradle plugin applies org.springframework.boot.aot itself when it sees org.graalvm.buildtools.native, so the native path already runs processAot and the JVM path deliberately does not. If the point was to run AOT processing on the JVM too, that is a separate decision worth a sentence, not a commented-out line.

Low: grails { indy = true } duplicates a convention the Grails Gradle plugin already sets

References:

  • end-to-end/native-i18n/build.gradle:36-41
  • grails-gradle/plugins/src/main/groovy/org/grails/gradle/plugin/core/GrailsGradlePlugin.groovy:1066-1071 (configureNativeImage sets indy.convention(true) when the GraalVM plugin is applied)

Not wrong, and setting it unconditionally means the JVM run is compiled the same way as the image, which is a reasonable choice. Note that with Groovy 5 it also makes no difference to the outcome, see the first finding. But the comment presents it as something the application has to do, when the plugin does it for any application that builds an image. Either drop the setting and let the convention prove itself (arguably more end-to-end), or keep it and say that it is there so the JVM half matches the native half rather than because an image needs it.

Low: the README's justification for the JDK requirement does not match the build

Reference: end-to-end/README.md:87-90: "grails-gradle pins no release target, so it stamps whatever JDK ran it onto its class files".

grails-gradle includes build-logic, and its four modules apply org.apache.grails.buildsrc.compile, whose configureJavaVersion sets options.release on every JavaCompile. What is true is that GroovyCompile has no release option, so the Groovy half of those modules targets the bytecode level of the JDK running the compiler. The advice (export the GraalVM JDK before publishing) is right; the reason given is not. And as the first finding shows, the GraalVM has to be the 25 line, so the README's implied "one JDK for everything" does not survive contact either: publish on 21, build the image with GRAALVM_HOME on 25, which the GraalVM plugin honours with toolchainDetection = false. Say "the Groovy sources in grails-gradle are compiled for the running JDK" or similar.

Low: the GraalVM plugin version is pinned in a new place, one step behind

Reference: end-to-end/gradle.properties:27, graalvmBuildtoolsVersion=1.1.7

Nothing else in the repository pins org.graalvm.buildtools (checked dependencies.gradle and grails-gradle), so a property is a fair place for it. Maven Central has 1.1.12 as the latest. Not blocking, but since this is the first pin it may as well start current, and a one-line comment saying why it lives in end-to-end/gradle.properties rather than dependencies.gradle would save the next person the search.

Nits

  • end-to-end/native-i18n/grails-app/init/nativei18n/Application.groovy:88: System.exit(0) is only on the success path. On failure the exception leaves main and the JVM exits non-zero only once every non-daemon thread has stopped. The context is closed in finally, so this works today, but a catch that prints and calls System.exit(1) would make the exit code independent of thread cleanup, which matters more for the native binary than the jar.
  • end-to-end/native-i18n/build.gradle:91: commandLine resolves the binary path eagerly with .get() at configuration time. Wiring it from nativeCompile's output (tasks.named('nativeCompile').flatMap { it.outputFile } or the binary's outputDirectory) keeps the path and the dependency in one place.
  • end-to-end/native-i18n/build.gradle:84: the comment on toolchainDetection = false explains why a failed image is a failure, not what the setting does (use GRAALVM_HOME/JAVA_HOME instead of a Gradle toolchain). Worth one clause.
  • end-to-end/native-i18n/grails-app/i18n/messages_fr.properties:19: "de l application" reads as a typo. Spring's ResourceBundleMessageSource does not pass a message with no arguments through MessageFormat, so l'application renders as written; if the apostrophe was dropped to be safe, l''application is the conventional spelling.
  • Neither new module applies org.apache.grails.buildsrc.vulnerability-scan, which legacy-commands, legacy-commands-plugin and spring-dependency-management all do. Probably deliberate for a fixture with two dependencies, but consistency is cheap.
  • README table rows are inserted between spring-dependency-management and taglib-index-incremental; the table was alphabetical.

Verified as correct

  • The plugin fixture does exercise the multi-word matching it claims: NativeMessagesGrailsPlugin yields native-messages via GrailsNameUtils.getPluginName in the descriptor, the runtime reports nativeMessages, and EffectiveI18nDescriptors normalises both through PluginUtils.normalizePluginName. The base name native-messages also passes GenerateI18nDescriptorTask.validatePluginNamespace.
  • The dotted base name is covered by I18nRuntimeHintsProcessor.toResourcePath, which is exactly the conversion the third case tests, and I18nEnvironmentPostProcessor.compose keeps an application-declared base name ahead of the discovered ones, so config.i18n.custom survives the merge.
  • fallback-to-system-locale: false is what makes the Locale.ENGLISH assertions land on the base bundle regardless of the machine's default locale. Good.
  • Apache license headers are present on every new file, including the bundles.

Beyond this PR

  • Native image support in Grails 8 depends on Groovy 6. Everything above reduces to this. #16176 should record it, and whoever owns the AOT work (Make Grails applications processable by Spring AOT (Leyden AOT Cache + GraalVM Native Image Support) #16094) should decide whether native image is an 8.0 claim or an 8.x-with-Groovy-6 claim, because the upgrade guide and the Gradle plugin's configureNativeImage convention currently imply the former.
  • Indy default for releases. README.md:103 is right that CompilePlugin defaults grailsIndy to false, so even once Groovy is fixed a released Grails cannot be imaged. That needs an issue or a decision before 8.0.0.

@codeconsole

Copy link
Copy Markdown
Contributor Author

Thank you for actually building the image — that is the half nobody had run, and it turned a "not executed yet" into a diagnosis. Everything below is fixed or accepted.

High — the native half cannot pass, and the README recipe does not produce a working image. Correct, and the README was worse than incomplete: it was missing the precondition that made it work the one time it did. That run used an unreleased build of GROOVY-12234 (apache/groovy#2766) forced onto runtimeClasspath; nothing about it was in the README, so following the README could only ever reproduce your result. Confirmed your diagnosis against the jars: groovy-5.1.2 has makeBootHandle but neither aotDispatch nor the ensureInitialized guard, while the GROOVY-12234 build has AotDispatch, aotDispatch and ensureInitialized.

The "Native image verification" section is rewritten. It now leads with the fact that -PnativeTests is expected to fail, gives both failure modes in a table (non-indy defines call-site classes, indy NPEs at makeBootHandle), names GROOVY-12234 and oracle/graal#10200 as the two preconditions, says the module has been run successfully exactly once and against what, and states that indy is necessary but not sufficient. Your point that "no released Grails can produce a working image" was true for the wrong reason in isolation is called out explicitly. The UnsupportedFeatureError and parallelism observations are now attributed to the toolchain they came from.

Medium — the dead catch. Right, and it is the more useful message of the two. check now treats actual == code as "its bundle never reached the message source"; the NoSuchMessageException wording is gone from the README and the Javadoc, which instead say that a missing bundle surfaces as a code resolving to itself because use-code-as-default-message is on.

Low — commented-out AOT probe. Removed.

Low — grails { indy = true } duplicates the convention. Kept, comment rewritten to say why: so the JVM half is compiled the same way as the image rather than being a second dialect of the same fixture, and noting it changes nothing about the outcome on the pinned Groovy.

Low — the JDK justification. Fixed. It now says GroovyCompile has no release option so the Groovy sources in grails-gradle target the running JDK, and that publish-JDK and image-JDK do not have to agree because toolchainDetection = false makes the plugin honour GRAALVM_HOME.

Low — GraalVM plugin version. 1.1.7 → 1.1.12, with a comment on why it is pinned in end-to-end/gradle.properties rather than dependencies.gradle.

Nits. All taken: explicit exit code on failure via a single close() in finally; i18nCheckOnNative takes its path from nativeCompile's outputFile provider; the toolchainDetection comment now says what the setting does; l'application; vulnerability-scan applied to both new modules; README table back in alphabetical order.

On the draft flag — the description claimed this "lets a missing hint actually be falsified", which is not true yet, and still referred to being a draft. Rewritten to say what the module does and does not currently prove.

On where this belongs. Leaving it on 8.0.x rather than moving it to 9.0.x. The JVM half stands on its own here — it guards the descriptor → base name → hint pipeline, the multi-word plugin normalisation and the dotted base name, and it is what caught #16179 — and the native half is inert behind -PnativeTests with no CI job, so it costs 8.0.x nothing while it cannot pass. Written this way it starts passing when the preconditions land instead of having to be written then, and it reaches 9.0.x by forward-merge anyway. What should be decided separately, as you say, is whether native image is an 8.0 claim at all, given configureNativeImage and the upgrade guide currently imply it is.

… native image

AOT processing on a JVM cannot falsify a resource hint: every bundle on a JVM
classpath is readable whether it was registered or not, so a missing hint shows
up only in a compiled image. The application resolves one code from each way a
bundle reaches the message source - the application's own bundle, a namespaced
plugin bundle, and a dotted base name the application configured - in English
and in a locale variant, plus an unknown code to prove MessageSourceProperties
bound as a whole.

This belongs on 9.0.x rather than 8.0.x. Dynamic Groovy in an image needs both
GROOVY-12234's AOT link mode, which ships in the 6.0.0-beta-2 this branch pins
and in no 5.x release, and invokedynamic, which this branch compiles with by
default and which 8.0.x deliberately forces off for published artifacts. Either
one missing is fatal to the image, so native image is not a Grails 8 capability.

The JVM half runs in check and needs nothing special. The native half is opt-in
behind -PnativeTests because it needs a GraalVM toolchain and minutes of CPU.
@codeconsole
codeconsole changed the base branch from 8.0.x to 9.0.x September 11, 2026 18:06
@codeconsole

Copy link
Copy Markdown
Contributor Author

@matrei I am just moving this to 9.0.x so it can be feature complete

@codeconsole
codeconsole force-pushed the feature/native-i18n-verification-8.0.x branch from 655879b to 0760a7c Compare September 11, 2026 18:40
Applying GraalVM's plugin already makes the Grails Gradle plugin default
invokedynamic on, so the native half compiles with it either way. The
JVM half resolves the same bundles whichever way it is compiled.
Declaring it in native-i18n alone gave that project a plugin classloader
of its own, so its vulnerabilityScan task could not be created: the
shared OsvVulnerabilityService had already been registered from another
project's classloader. Declared once at the root with apply false, every
project shares the same classes and native-i18n still applies the plugin
only under -PnativeTests.
9.0.x is on Groovy 6.0.0, which carries the AOT link mode and ships its
own native-image configuration, not 6.0.0-beta-2. Invokedynamic is on
for the library modules only: the plugin modules, including grails-gsp,
grails-sitemesh3 and grails-cache from the web starter, still follow the
Grails Gradle plugin's default until apache#16165 changes it.
The first CI run of the native step failed in "Initializing" with
"Could not find target method: ...IndyInterface.invalidateSwitchPoints()",
the bundled Groovy substitution of oracle/graal#10200. setup-graalvm
resolved java-version '25' to GraalVM CE 25.0.2, the last release tagged
by JDK version, and that release still has the substitution. Releases
since are tagged by GraalVM version (graal-25.2.4 and later), which a
java-version alone never selects.

Asking for version '25.2' selects graal-25.2.4, the release the image
was verified with locally. The README said the fix was in "the 25 line";
it now says which releases fail and how to ask for one that works.
Dynamically compiled code compiles `{ ... } as SomeInterface` to an indy call to asType taking the
Closure and the interface's class literal, loaded right before it, rather than to a cast. Only the
cast was found, so a dynamic plugin descriptor's beanRegistrar() worked in an image only because
another plugin coerced a closure to the same interface under static compilation.

A closure dynamically compiled code passes to a method is an ordinary call with a Closure argument
and cannot be found from the bytecode; the javadoc and the guide now say only the forms that name
the interface are found.
Only a class registered for the setProperty lookup was asked whether every type its bytecode names
loads. A Groovy enum, a trait helper and a class with members Spring injects were asked only whether
they load, which a class does without what its method bodies name, so one compiled against an
optional integration the application lacks was registered and would fail the image build.

Every class the scan read is now asked both, and the spec covers each of those paths and a class
whose file is found but which does not load.
@codeconsole
codeconsole force-pushed the feature/native-i18n-verification-8.0.x branch from 260d1bb to 3dee352 Compare October 22, 2026 19:24
@codeconsole

codeconsole commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor Author

@jdaugherty Thanks for checking the native run. Both points from the review body are done:

  • Description: the double-injection paragraph is gone. I also scoped the Limitations section to starting the application, to match your guide comment, and retitled the PR to "Start Grails as a native image…".
  • History: the 11 commits that duplicated 8.0 (fix): Inject the beans generated ahead of time only once #16709 are gone. Every commit after them was replayed in order (3dee35205b), so the branch now has 35 commits of its own, and the fix appears in the history once, through 9.0.x. The new head has exactly the same files as the head before the rewrite.

The three inline comments are answered in their threads, with the commits that address them.

@jdaugherty jdaugherty left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked on 904776b. The three inline asks are done as the threads describe, so I've resolved them:

  • The guide paragraph scopes the list to starting the application and says what a request reaches is still recorded, the framework's reflection on that path included.
  • FindingMethodVisitor finds a dynamic as with a class literal. DynamicCoercionFixture compiles to ldc IntUnaryOperator; invokedynamic invoke:(Lgroovy/lang/Closure;Ljava/lang/Class;) (javap on the test classes) and the proxy hint is registered. One edge of the new wording is inline.
  • The enum, trait-helper and injected-member paths go through isRegistrable, and the two new features fail without it.

The history is as described: 35 commits of the branch's own, the tree right before the three fixes is byte-identical to 1eca3c0, so the rewrite dropped nothing but the 11 duplicate commits, and the merge after the fixes (904776b) resolves nothing by hand. The description no longer lists the double-injection fix.

CI at 904776b: all 90 checks green. The End to End job built the image on GraalVM CE 25.2.4 and i18nCheckOnNative passed, with 5,028 types and 31,574 methods registered for reflection (5,022 and 31,564 at 1eca3c0) and the same 142.50 MiB binary. Locally the 22 specs in org.apache.grails.core.aot pass (158 tests), the six new features among them.

* {@code BeanRegistrar} often is -- becomes it through a JDK proxy created as the call is made. An image
* creates a proxy only for an interface it was told about, and refuses the rest with
* {@code MissingReflectionRegistrationError}. Only a coercion that names the interface is found: any in
* statically compiled code, and an {@code as} with a class literal in dynamically compiled code. A closure

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked what as compiles to in a dynamically compiled class on Groovy 6.0.0. The receiver's static type matters as much as the class literal: the call site's descriptor says Closure only when the compiler knows the receiver is one.

{ int o -> o * 2 } as IntUnaryOperator        ldc IntUnaryOperator; invokedynamic invoke:(Lgroovy/lang/Closure;Ljava/lang/Class;)   found
Closure c = { ... }; c as IntUnaryOperator    the same                                                                         found
def c = { ... }; c as IntUnaryOperator        ldc IntUnaryOperator; invokedynamic invoke:(Ljava/lang/Object;Ljava/lang/Class;)    not found
make() as IntUnaryOperator                    the same, an Object receiver                                                     not found

The last two still make a JDK proxy at run time, and this sentence, the guide bullet at line 118 of deploymentAot.adoc ("wherever dynamically compiled code names the interface with as") and the description all read as if naming the interface is enough. Either way of closing that works for me:

  • say the closure has to be a closure literal or a Closure-typed expression, here and in the guide bullet; or
  • accept an Object receiver for asType as well. Groovy proxies a Map coerced to an interface the same way, so that case is right too; the cost is a proxy hint for an as Set, as List or as Map in dynamic code, which the image never uses.

Not blocking: the framework's own as BeanRegistrar coercions are closure literals, which DynamicCoercionFixture covers.

@codeconsole codeconsole Oct 24, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went with the second option, one step wider. On Groovy 6.0.0 I compiled each receiver shape in a dynamic and a @CompileStatic class. Every as there is an indy call to asType, since statically compiled code doesn't cast for as either, and the receiver in the descriptor is whatever the compiler knows:

as on dynamic static JDK proxy at run time
closure literal, Closure variable (Closure, Class) (Closure, Class) yes
def variable, method result (Object, Class) (Closure, Class) yes
map literal (Map, Class) (Map, Class) yes

Accepting Object alone would still miss a map literal, whose receiver is Map in both. The framework has one: ConfigProperties.propertyNames() coerces a map of closures as Enumeration, and that had no proxy hint.

452e34e accepts any receiver for an asType call right after a class literal naming an interface. The spec is now data-driven over the seven forms above. Each row runs its fixture, asserts the result is a JDK proxy, and asserts the hint. The four rows the old visitor missed (def, method result, both map literals) fail against it, as does a new feature for ConfigProperties.propertyNames().

The cost, measured on native-i18n's runtime classpath: the wider rule adds 6 interfaces. Only Enumeration is a real proxy. The other five are never proxied:

  • Collection, List, Map and Set, from collection conversions;
  • Promise, from a Future that CachedThreadPoolPromiseFactory coerces.

It found a seventh, Runnable, in EmbeddedDatabaseShutdownHook. In ShutdownOperations.addOperation { … } as Runnable, the as bound to the void call's result, so it converted nothing, and the closure is a Runnable already. 6f481ef drops the as. The hook had no tests, so it adds a spec covering which databases it shuts down and when.

Accepting any receiver also finds value as SomeSealedInterface. The JDK refuses to proxy a sealed interface, so 1f0e69b skips those, with a fixture that fails without the check.

The javadoc and the guide bullet at line 118 now say a closure or a map is found wherever any code names the interface with as, whatever it declares the value as. The javadoc also says an as that converts without a proxy costs an unused hint. The description says the same.

`as` with a class literal compiles to a call to asType, in statically and dynamically compiled code
alike, and the call declares the value as a Closure only when the compiler knows it is one. A def
variable or a method's result is declared as an Object, and a map literal as a Map, which Groovy
turns into an interface through a JDK proxy just as it does a closure. Those were not found, so
ConfigProperties.propertyNames(), which coerces a map literal to Enumeration, had no proxy hint.

Any asType call right after a class literal naming an interface is now found. An `as` that converts
without a proxy, such as `as List`, then registers a proxy the image never makes: on native-i18n's
classpath the rule adds seven interfaces, and only Enumeration is proxied.
Now that any `as` naming an interface is found, `value as SomeSealedInterface` registers a proxy for
it. The JDK refuses to proxy a sealed interface, so a value can only be coerced to one it already
implements, and the hint is of no use.
In `ShutdownOperations.addOperation { ... } as Runnable` the `as` binds to the call's void result,
so it coerced null and did nothing; the closure reaches addOperation as it is, being a Runnable
already. Now that any `as` naming an interface is registered for a proxy, it cost every image an
unused Runnable proxy hint.

The hook had no tests. The spec covers its lifecycle, which databases it shuts down, and that the
shutdown waits for the shutdown operations to run.

@jamesfredley jamesfredley left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not approving. A bean a registrar defines as a Spring class is marked injected, so native startup has no constructor hint for it. 9.0.x is the right line for native-image startup.

A registrar's beans are left out of the generated code and declared again
as the application starts, so Spring creates them through their
constructor whatever their package. A Spring class is now treated as
created by the generated code only when its definition is not a
registrar's; an image built without the hint failed to start with
"No default constructor found".
@testlens-app

testlens-app Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

✅ All tests passed ✅

⚠️ TestLens detected flakiness ⚠️

Failed Jobs without Test Failures

❌ CI / Hibernate7 Functional Tests (Java 25, indy=false)

Test Summary

Tip

Inspect all details with the TestLens CLI: testlens pr 16180

CI / Functional Tests (Java 21, indy=true) > :grails-test-examples-geb:integrationTest

Test Runs Flakiness
PerTestRecordingSpec > the recordings of the previous two tests are different ❌ ✅ 1% 🟡

🏷️ Commit: 68fa0b8
▶️ Tests: 11307 executed
⚪️ Checks: 98/98 completed

Test Failures

PerTestRecordingSpec > the recordings of the previous two tests are different (:grails-test-examples-geb:integrationTest in CI / Functional Tests (Java 21, indy=true) | Attempt 1/2)
Condition not satisfied:

secondRecording.length() > MIN_MEANINGFUL_RECORDING_BYTES
|               |        | |
|               2523     | 5000
|                        false
build/gebContainer/recordings/20261029_191208/PASSED-PerTestRecordingSpec_setup_running_a_second_test_to_create_another_recording-20261029-191538.mp4

	at org.demo.spock.PerTestRecordingSpec.the recordings of the previous two tests are different(PerTestRecordingSpec.groovy:105)

Rerun Controls

Click the checkbox to trigger a rerun:

  • Rerun jobs

Learn more about TestLens at testlens.app/docs.

@jamesfredley jamesfredley left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A registrar-defined Spring bean keeps its constructor hint. A supplier-created bean and a factory-method bean still do not. 9.0.x is the right line.

@codeconsole
codeconsole merged commit d801680 into apache:9.0.x Oct 29, 2026
171 of 175 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants