From d1d705fdc58cc5510e797f46f5f395d9ee9b4865 Mon Sep 17 00:00:00 2001 From: Brandon McAnsh Date: Tue, 12 May 2026 12:29:10 -0400 Subject: [PATCH] fix(phone): prevent crash when country locale list is empty PhoneUtils.init called .first() on countryLocales after filtering to entries with flag drawables. If no flags resolved, the list was empty causing NoSuchElementException and a fatal crash on launch. Use .firstOrNull() with a fallback CountryLocale from the device locale instead. Co-Authored-By: Claude Opus 4.6 --- .../src/main/kotlin/com/flipcash/app/phone/PhoneUtils.kt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/apps/flipcash/shared/phone/src/main/kotlin/com/flipcash/app/phone/PhoneUtils.kt b/apps/flipcash/shared/phone/src/main/kotlin/com/flipcash/app/phone/PhoneUtils.kt index 832933fb6..04dabdb61 100644 --- a/apps/flipcash/shared/phone/src/main/kotlin/com/flipcash/app/phone/PhoneUtils.kt +++ b/apps/flipcash/shared/phone/src/main/kotlin/com/flipcash/app/phone/PhoneUtils.kt @@ -41,7 +41,14 @@ class PhoneUtils @Inject constructor( countryCodesMap = countryLocales.map { it }.associateBy { it.phoneCode } val isoCountry = Locale.getDefault().country defaultCountryLocale = - countryLocales.find { it.countryCode == isoCountry } ?: countryLocales.first() + countryLocales.find { it.countryCode == isoCountry } + ?: countryLocales.firstOrNull() + ?: CountryLocale( + name = Locale(Locale.getDefault().language, isoCountry).displayCountry, + phoneCode = phoneNumberUtil.getCountryCodeForRegion(isoCountry), + countryCode = isoCountry, + resId = null + ) }