ankidroid / Anki-Android

AnkiDroid: Anki flashcards on Android. Your secret trick to achieve superhuman information retention.
GNU General Public License v3.0
8.73k stars 2.24k forks source link

Handle locale name being empty in preferences #17473

Closed lukstbit closed 1 day ago

lukstbit commented 1 day ago

Purpose / Description

Fixes a recent acra report where the device locale was not available. This crashes the preferences code because we query the displayName of the locale to determine if the app language is rtl or not:

Caused by: java.lang.StringIndexOutOfBoundsException: length=0; index=0
    at java.lang.String.charAt(Native Method)
    at com.ichi2.anki.LanguageUtils.appLanguageIsRTL(LanguageUtils.java:46)
    at com.ichi2.preferences.HeaderPreference$Companion.buildHeaderSummary(HeaderPreference.kt:69)
    at com.ichi2.preferences.HeaderPreference.<init>(HeaderPreference.kt:45)
    at com.ichi2.preferences.HeaderPreference.<init>(HeaderPreference.kt:31)
    at com.ichi2.preferences.HeaderPreference.<init>(HeaderPreference.kt)
    ... 35 more

I've modified the problematic method to handle an empty locale.displayName and to default to false(not rtl language) when that happens.

How Has This Been Tested?

Ran the related test, tried using rtl vs non rtl in preferences. I don't know how to test a no locale displayName.

Checklist