Check null before passing to Integer.parseInt

Just after user data is cleared, user preference associated with
PREF_KEYBOARD_LAYOUT is always empty. In such case, we might
want to return the default value immediately, rather than
calling Integer.parseInt(null) and catching NumberFormatException
unnecessarily.

BUG: 13472379
Change-Id: I8dca9a22780d057013c032bd1f56e730dcada3ce
main
Yohei Yukawa 2014-03-24 20:45:37 +09:00
parent a17195224b
commit f1f5ed542d
1 changed files with 3 additions and 0 deletions

View File

@ -273,6 +273,9 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
public static int readKeyboardThemeIndex(final SharedPreferences prefs, final Resources res) {
final int defaultThemeIndex = readDefaultKeyboardThemeIndex(res);
final String themeIndexString = prefs.getString(PREF_KEYBOARD_LAYOUT, null);
if (themeIndexString == null) {
return defaultThemeIndex;
}
try {
return Integer.parseInt(themeIndexString);
} catch (final NumberFormatException e) {