Skip to content

Commit 190b66b

Browse files
committed
Recover from missing bundle.
1 parent 2104484 commit 190b66b

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

hipparchus-core/src/main/java/org/hipparchus/exception/Localizable.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
import java.io.Serializable;
2525
import java.util.Locale;
26+
import java.util.MissingResourceException;
2627
import java.util.ResourceBundle;
2728

2829
/**
@@ -57,15 +58,19 @@ public interface Localizable extends Serializable {
5758
*/
5859
default String getLocalizedString(final String baseName, final String key, final Locale locale) {
5960

60-
final ResourceBundle bundle = ResourceBundle.getBundle(baseName, locale, new UTF8Control());
61-
if (bundle.getLocale().getLanguage().equals(locale.getLanguage()))
62-
{
63-
final String translated = bundle.getString(key);
64-
if (!(translated.isEmpty() || translated.toLowerCase().contains("missing translation")))
61+
try {
62+
final ResourceBundle bundle = ResourceBundle.getBundle(baseName, locale, new UTF8Control());
63+
if (bundle.getLocale().getLanguage().equals(locale.getLanguage()))
6564
{
66-
// the value of the resource is the translated format
67-
return translated;
65+
final String translated = bundle.getString(key);
66+
if (!(translated.isEmpty() || translated.toLowerCase().contains("missing translation")))
67+
{
68+
// the value of the resource is the translated format
69+
return translated;
70+
}
6871
}
72+
} catch (MissingResourceException mre) { // NOPMD
73+
// do nothing here
6974
}
7075

7176
// either the locale is not supported or the resource is not translated, or

0 commit comments

Comments
 (0)