Skip to content

BUGFIX: message bundles silently failing to resolve in development - #16179

Merged
jdaugherty merged 1 commit into
apache:8.0.xfrom
codeconsole:fix/urlmappings-factory-bean-object-type-8.0.x
Aug 20, 2026
Merged

jdaugherty merged 1 commit into
apache:8.0.xfrom
codeconsole:fix/urlmappings-factory-bean-object-type-8.0.x

Conversation

@codeconsole

Copy link
Copy Markdown
Contributor

In development, every message bundle contributed by a plugin, and every base name an application configured itself, silently fails to resolve. Spring Boot's messageSource is built with only the default messages base name, and nothing warns:

NoSuchMessageException: No message found under code 'my.plugin.message' for locale 'en'

Deployed applications are unaffected — only reload mode builds the holder as a proxy — so this is grails run-app, every Gradle JavaExec, and every integration run.

Cause

A factory bean's produced type has to be answerable from the bean definition, because a property value cannot be. Asked for the type of grailsUrlMappingsHolder, Spring builds a constructor-only ProxyFactoryBean — no property values applied, so no targetSource and no proxyInterfaces — whose getObjectType() returns null. Spring then falls back to creating the factory bean in full.

That resolves the target source and the inner UrlMappingsHolderFactoryBean, evaluates every URL mapping, reaches the constraints machinery and its List<MessageSource> injection, and so creates Spring Boot's message source — all while bean definition registry post-processors are still running. Anything created that early misses ConfigurationPropertiesBindingPostProcessor, so MessageSourceProperties is never bound and keeps its constructor defaults.

It is not only the base names: encoding, cache-duration and fallback-to-system-locale are lost with them.

Fix

Each factory-bean definition declares what it produces through FactoryBean.OBJECT_TYPE_ATTRIBUTE, which Spring consults before instantiating anything:

proxy.setAttribute(FactoryBean.OBJECT_TYPE_ATTRIBUTE, UrlMappings)

By-type autowiring of UrlMappingsHolder keeps working — that is why these definitions live in a post-processor rather than the BeanRegistry API — and the hot-swap target source is untouched, so reload still works.

Reload mode is additionally switched off when running generated bean definitions: AOT code generation drops custom definition attributes, and hot-swapping mappings is meaningless in an image.

Test

The regression test issues the eager by-type lookup directly against a bare DefaultListableBeanFactory, so it reproduces with no Grails runtime and no ordering luck. It fails without the fix.

Notes

  • setLazyInit(true) cannot help here: the lazy-init gate is bypassed when a by-type scan runs with allowEagerInit, and these definitions were already lazy.
  • Promoting the inner holder to a named top-level bean does not work — it adds a second UrlMappings candidate and the application fails to start with required a single bean, but 2 were found.

…ated to find out

In development, every message bundle contributed by a plugin, and every base name
an application configured itself, silently failed to resolve. Spring Boot's
messageSource was built with only the default base name, and nothing warned.

The produced type of a factory bean has to be answerable from the bean
definition, because a property value cannot be. Asked for the type of
grailsUrlMappingsHolder without it, Spring builds a constructor-only
ProxyFactoryBean - no property values applied, so no targetSource and no
proxyInterfaces - whose getObjectType() returns null, and then falls back to
creating the factory bean in full. That resolves the target source and the inner
UrlMappingsHolderFactoryBean, evaluates every mapping, reaches the constraints
machinery and its List<MessageSource> injection, and so creates Spring Boot's
message source - all while bean definition registry post processors are still
running. Anything created that early misses
ConfigurationPropertiesBindingPostProcessor, so MessageSourceProperties is never
bound and keeps its constructor defaults. Not just the base names: encoding,
cache-duration and fallback-to-system-locale are lost with it.

Only the reload branch built the proxy over an inner bean, so deployed
applications were unaffected and the whole of development was not.

Each factory-bean definition now declares its produced type through
FactoryBean.OBJECT_TYPE_ATTRIBUTE, which Spring consults before instantiating
anything. Reload mode is also switched off when running generated bean
definitions, since AOT code generation drops custom definition attributes and
hot-swapping mappings is meaningless in an image.

The regression test issues the eager by-type lookup directly against a bare
DefaultListableBeanFactory, so it reproduces with no Grails runtime and no
ordering luck: it asserts the holder is still found by type, and that nothing was
created in order to answer.
@testlens-app

testlens-app Bot commented Aug 20, 2026 •

Copy link
Copy Markdown

✅ All tests passed ✅

⚠️ TestLens detected flakiness ⚠️

Test Summary

CI - Groovy Joint Validation Build / Build Grails with Groovy snapshot (shard 1) > :grails-data-mongodb-core:test

Test Runs Flakiness
MongoTransactionSpec > test a REQUIRES_NEW inner transaction commits independently of a rolled back outer transaction ❌ ✅ 2% 🟡
MongoTransactionSpec > test a committed transaction persists all writes atomically ❌ ✅ 2% 🟡
MongoTransactionSpec > test a findOneAndDelete via the MongoEntity API participates in the transaction ❌ ✅ 2% 🟡
MongoTransactionSpec > test a per-transaction timeout is rejected rather than silently ignored ❌ ✅ 2% 🟡
MongoTransactionSpec > test a rolled back transaction discards a native Long id entity (id generation is non-transactional) ❌ ✅ 2% 🟡
MongoTransactionSpec > test a rolled back transaction discards all writes on the server ❌ ✅ 2% 🟡
MongoTransactionSpec > test native Long identifier generation works for entities committed in a transaction ❌ ✅ 2% 🟡
MongoTransactionSpec > test read-your-writes within an active transaction ❌ ✅ 2% 🟡
MongoTransactionSpec > test writes across multiple collections roll back together ❌ ✅ 2% 🟡

🏷️ Commit: 9a47272
▶️ Tests: 53300 executed
⚪️ Checks: 77/77 completed


Learn more about TestLens at testlens.app/docs.

@codecov

codecov Bot commented Aug 20, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 60.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 53.6348%. Comparing base (d0c68dc) to head (9a47272).

Files with missing lines Patch % Lines
...plugins/web/mapping/UrlMappingsGrailsPlugin.groovy 0.0000% 0 Missing and 2 partials ⚠️
Additional details and impacted files

Impacted file tree graph

@@                Coverage Diff                 @@
##                8.0.x     #16179        +/-   ##
==================================================
- Coverage     53.6425%   53.6348%   -0.0076%     
+ Complexity      19783      19778         -5     
==================================================
  Files            2086       2086                
  Lines           99630      99633         +3     
  Branches        17594      17594                
==================================================
- Hits            53444      53438         -6     
- Misses          38542      38549         +7     
- Partials         7644       7646         +2     
Files with missing lines Coverage Δ
...ing/UrlMappingsBeanDefinitionsPostProcessor.groovy 86.4865% <100.0000%> (+1.1924%) ⬆️
...plugins/web/mapping/UrlMappingsGrailsPlugin.groovy 44.1176% <0.0000%> (-2.9412%) ⬇️

... and 2 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 changed the title Fix message bundles silently failing to resolve in development BUGFIX: message bundles silently failing to resolve in development Aug 20, 2026
@jdaugherty
jdaugherty merged commit 57e3aa7 into apache:8.0.x Aug 20, 2026
83 of 85 checks passed
codeconsole added a commit to codeconsole/grails-core that referenced this pull request Oct 22, 2026
The Grails Gradle plugin starts every JavaExec in development, so the JVM
half started differently from the image, which starts in production from
the build information packaged into it. It now runs in production, and once
more in development, where bundles stopped resolving until apache#16179 and where
this run found it.

Each run, the image's included, is told which environment to expect through
i18n.check.environment and fails in any other, so a run that silently
started in the wrong one cannot pass.
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.

3 participants