Skip to content

fix: return English descriptions for Locale.ENGLISH regardless of def…#1304

Open
derTobsch wants to merge 3 commits into
mainfrom
1294-fallback-to-eng
Open

fix: return English descriptions for Locale.ENGLISH regardless of def…#1304
derTobsch wants to merge 3 commits into
mainfrom
1294-fallback-to-eng

Conversation

@derTobsch

Copy link
Copy Markdown
Contributor

…ault locale

ResourceBundle.getBundle() falls back to Locale.getDefault() before the base bundle when the requested locale has no dedicated resource file. Since there is no country_descriptions_en.properties (the base .properties holds English text), requesting Locale.ENGLISH on a system with a German/French default locale would return German/French descriptions instead of English ones.

The fix temporarily sets the thread default locale to Locale.ROOT during getBundle() calls, forcing ResourceBundle to skip the default-locale fallback and go directly to the base bundle. The original default locale is restored in a finally block, ensuring thread safety.

closes #1294

…ault locale

ResourceBundle.getBundle() falls back to Locale.getDefault() before the base
bundle when the requested locale has no dedicated resource file. Since there is
no country_descriptions_en.properties (the base .properties holds English text),
requesting Locale.ENGLISH on a system with a German/French default locale would
return German/French descriptions instead of English ones.

The fix temporarily sets the thread default locale to Locale.ROOT during
getBundle() calls, forcing ResourceBundle to skip the default-locale fallback
and go directly to the base bundle. The original default locale is restored in
a finally block, ensuring thread safety.

closes #1294
@derTobsch derTobsch force-pushed the 1294-fallback-to-eng branch from a4d6c57 to c67cc17 Compare June 16, 2026 11:34
Add tests for previously uncovered methods:
- getCountryDescription(String) with various default locales
- getHolidayDescription(String) with various default locales
- getResource(String) for existing and nonexistent resources
- getResource(String, boolean) searchOnlyInJar variant
- UNDEFINED constant value

closes #1294
@sonarqubecloud

Copy link
Copy Markdown

Locale.setDefault(Locale.FRANCE);

// Request English description for France
final String description = ResourceUtil.getCountryDescription(Locale.ENGLISH, "fr");
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.

Wrong country descriptions for english Locale in some non-english default Locale environments

1 participant