Android icon indicating copy to clipboard operation
Android copied to clipboard

Possible NPE in currency handling

Open TheLastProject opened this issue 3 years ago • 2 comments

In the currency sorting logic, a locale is explicitly given:

https://github.com/CatimaLoyalty/Android/blob/cae95d257768546dd4069c3a33f80d6112fa671d/app/src/main/java/protect/card_locker/LoyaltyCardEditActivity.java#L441-L459

However, currencyList, which is based on currencies, is created using an implicit locale: https://github.com/CatimaLoyalty/Android/blob/cae95d257768546dd4069c3a33f80d6112fa671d/app/src/main/java/protect/card_locker/LoyaltyCardEditActivity.java#L307

Mixing implicit and explicit locale can probably create all kinds of nasty bugs, the logic of this code needs to be re-read to ensure it is actually safe and if not, it needs to be fixed.

TheLastProject avatar Jan 23 '22 19:01 TheLastProject

AFAIK it's safe. I would be very surprised if you can have an unset DISPLAY locale (which is what Currency.getSymbol() uses).

Note that there's a difference between getting the currency for a specific locale with Currency.getInstance(locale) -- which only works for locales including a region (e.g. en_GB, ja_JP) but not for e.g. en or ja as currency varies by region, not language -- and then getting the symbol for that currency in the current DISPLAY locale -- which is just ja when the app is set to Japanese with the internal language selector -- with Currency.getSymbol().

obfusk avatar Jun 17 '23 11:06 obfusk

Though as #1322 shows, the DISPLAY locale can change, causing bugs.

obfusk avatar Jun 17 '23 11:06 obfusk