From 6f9c6f2c64e6983b85adfe97335b5feb99a9937f Mon Sep 17 00:00:00 2001
From: Satoshi Kataoka <satok@google.com>
Date: Thu, 6 Jun 2013 10:57:47 +0900
Subject: [PATCH] Fix a possible NPE

Bug: 9301208
Change-Id: Id120c99ab9ef698d16cf7b8beea30c98c95d23a1
---
 java/src/com/android/inputmethod/latin/Settings.java | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/java/src/com/android/inputmethod/latin/Settings.java b/java/src/com/android/inputmethod/latin/Settings.java
index 9fefb58a65..a6149c6ec3 100644
--- a/java/src/com/android/inputmethod/latin/Settings.java
+++ b/java/src/com/android/inputmethod/latin/Settings.java
@@ -21,6 +21,7 @@ import android.content.SharedPreferences;
 import android.content.pm.ApplicationInfo;
 import android.content.res.Resources;
 import android.preference.PreferenceManager;
+import android.util.Log;
 
 import com.android.inputmethod.latin.LocaleUtils.RunInLocale;
 
@@ -28,6 +29,7 @@ import java.util.HashMap;
 import java.util.Locale;
 
 public final class Settings implements SharedPreferences.OnSharedPreferenceChangeListener {
+    private static final String TAG = Settings.class.getSimpleName();
     // In the same order as xml/prefs.xml
     public static final String PREF_GENERAL_SETTINGS = "general_settings";
     public static final String PREF_AUTO_CAP = "auto_cap";
@@ -114,6 +116,12 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
 
     @Override
     public void onSharedPreferenceChanged(final SharedPreferences prefs, final String key) {
+        if (mSettingsValues == null) {
+            // TODO: Introduce a static function to register this class and ensure that
+            // loadSettings must be called before "onSharedPreferenceChanged" is called.
+            Log.w(TAG, "onSharedPreferenceChanged called before loadSettings.");
+            return;
+        }
         loadSettings(mCurrentLocale, mSettingsValues.mInputAttributes);
     }
 
-- 
GitLab