From f1f5ed542d43566f30e9f03f98de9bef717465ce Mon Sep 17 00:00:00 2001 From: Yohei Yukawa Date: Mon, 24 Mar 2014 20:45:37 +0900 Subject: [PATCH] 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 --- java/src/com/android/inputmethod/latin/settings/Settings.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/java/src/com/android/inputmethod/latin/settings/Settings.java b/java/src/com/android/inputmethod/latin/settings/Settings.java index 964bf2246..1ba92adb1 100644 --- a/java/src/com/android/inputmethod/latin/settings/Settings.java +++ b/java/src/com/android/inputmethod/latin/settings/Settings.java @@ -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) {