Skip to content

Conversation

Copilot
Copy link

@Copilot Copilot AI commented Oct 8, 2025

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:

// Set JVM default locale to German
Locale.setDefault(new Locale("de", "DE"));

DefaultI18N i18n = new DefaultI18N();
i18n.initialize();

// Request a locale that doesn't have a bundle (Hebrew - Israel)
String result = i18n.getString("project-info-reports", new Locale("iw", "IL"), "report.ci-management.access");

// Expected: "Access" (from root bundle)
// Actual (before fix): "Zugriff" (from German bundle)

Solution

Updated all ResourceBundle.getBundle() calls to use ResourceBundle.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_USen → root).

Changes:

  • Modified cacheBundle() method to use no-fallback control
  • Modified getBundleIgnoreException() method to use no-fallback control
  • Updated test expectations to match the corrected behavior
  • Added new test case to verify the fix

Behavior Change

Before:

  • Locale fallback: requested_localeJVM_default_localeroot
  • Example: iw_ILde_DEroot (stops at de_DE if bundle exists)

After:

  • Locale fallback: requested_localeroot
  • Example: iw_ILroot (skips de_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

This section details on the original issue you should resolve

<issue_title>DefaultI18N is prope to loading default locale data even if not requested</issue_title>
<issue_description>This class uses the default ResourceBundles behavior to use the default locale when no bundle for the desired one is not present. With default locale de_DE:

		DefaultI18N i18n = new DefaultI18N();
		i18n.initialize();
		System.out.println(i18n.getString("project-info-reports", new Locale("iw", "IL"), "report.ci-management.access")); 

expected is to get the root bundle with: "Access". But we get: "Zugriff" because of the locale.

This class misses to pass ResourceBundle.Control.getNoFallbackControl(ResourceBundle.Control.FORMAT_PROPERTIES) to the resource bundle.

This was found during work on Maven Project Info Reports Plugin and Maven Surefire while working with custom bundles.</issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes #4

💡 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.

@Copilot Copilot AI changed the title [WIP] Fix DefaultI18N to prevent fallback to default locale Fix DefaultI18N to prevent fallback to JVM default locale Oct 8, 2025
@Copilot Copilot AI requested a review from slachiewicz October 8, 2025 21:44
Copilot finished work on behalf of slachiewicz October 8, 2025 21:44
@slachiewicz slachiewicz marked this pull request as ready for review October 9, 2025 12:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DefaultI18N is prope to loading default locale data even if not requested

3 participants