Recently I found out from Firebase Crashlytics that some HTC/Fortuneship devices crashes with the next exception and I can't understand why
val formattedViews: String
get() = String.format(Locale.getDefault(), "%,d %s", viewCount, Util.getString(R.string.views))
I don't get how such exception can happen in this code
Is there something wrong with those devices?
This is a bug in the JDK shipping with Android 7: https://bugs.openjdk.java.net/browse/JDK-8167567
You are passing Locale.getDefault()
to format()
, which is the same as not specifying a locale at all. The only known workaround appears to be to use a known-good locale to do the formatting (e.g. Locale.US
), but of course this means you won't get locale-specific thousands groupings for users outside the US.
Or you could change your format specification to not use groupings (i.e. %d
without the comma).
Perhaps you could catch
the exception and fall back to US formatting for users who would otherwise crash? That's what these guys did: https://github.com/wordpress-mobile/WordPress-Android/pull/5604/files