Fix NPE when locale specifies unknown country code.

This commit is contained in:
jmacxx 2022-02-05 11:21:59 -06:00
parent fcb13ed772
commit 78e9ed2382
No known key found for this signature in database
GPG Key ID: 155297BABFE94A1B
2 changed files with 11 additions and 2 deletions

View File

@ -23,6 +23,9 @@ import javafx.beans.property.SimpleObjectProperty;
import java.util.Locale;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class GlobalSettings {
private static boolean useAnimations = true;
private static Locale locale;
@ -32,6 +35,7 @@ public class GlobalSettings {
static {
locale = Locale.getDefault();
log.info("Locale info: {}", locale);
// On some systems there is no country defined, in that case we use en_US
if (locale.getCountry() == null || locale.getCountry().isEmpty())

View File

@ -277,8 +277,13 @@ public final class Preferences implements PersistedDataHost, BridgeAddressProvid
prefPayload.setUserLanguage(GlobalSettings.getLocale().getLanguage());
prefPayload.setUserCountry(CountryUtil.getDefaultCountry());
GlobalSettings.setLocale(new Locale(prefPayload.getUserLanguage(), prefPayload.getUserCountry().code));
TradeCurrency preferredTradeCurrency = checkNotNull(CurrencyUtil.getCurrencyByCountryCode(prefPayload.getUserCountry().code),
"preferredTradeCurrency must not be null");
TradeCurrency preferredTradeCurrency = CurrencyUtil.getCurrencyByCountryCode("US"); // default fallback option
try {
preferredTradeCurrency = CurrencyUtil.getCurrencyByCountryCode(prefPayload.getUserCountry().code);
} catch (IllegalArgumentException ia) {
log.warn("Could not determine currency for country {} [{}]", prefPayload.getUserCountry().code, ia.toString());
}
prefPayload.setPreferredTradeCurrency(preferredTradeCurrency);
setFiatCurrencies(CurrencyUtil.getMainFiatCurrencies());
setCryptoCurrencies(CurrencyUtil.getMainCryptoCurrencies());