Fix DefaultI18N to prevent fallback to JVM default locale #26
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
The
DefaultI18N
class was incorrectly falling back to the JVM's default locale when a requested locale bundle was not available. This caused unexpected localization behavior, particularly when working with custom bundles in projects like Maven Project Info Reports Plugin and Maven Surefire.Example of the bug:
Solution
Updated all
ResourceBundle.getBundle()
calls to useResourceBundle.Control.getNoFallbackControl(ResourceBundle.Control.FORMAT_DEFAULT)
, which prevents fallback to the JVM's default locale while still allowing proper fallback within the locale chain (e.g.,en_US
→en
→ root).Changes:
cacheBundle()
method to use no-fallback controlgetBundleIgnoreException()
method to use no-fallback controlBehavior Change
Before:
requested_locale
→JVM_default_locale
→root
iw_IL
→de_DE
→root
(stops atde_DE
if bundle exists)After:
requested_locale
→root
iw_IL
→root
(skipsde_DE
)This ensures that when a specific locale bundle is not available, the application falls back to the neutral root bundle rather than inadvertently using the JVM's locale, which may not be appropriate for the user's actual locale preference.
Testing
All existing tests pass with updated expectations, and a new test
testNoFallbackToDefaultLocale()
validates the fix works correctly.Fixes issue where DefaultI18N was prone to loading default locale data even when not requested.
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.