Merge "Clean up two word correction"
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
index 4967a5e..cb80d05 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
@@ -149,7 +149,6 @@
         if (mainKeyboardId.isPhoneKeyboard()) {
             mState.setSymbolsKeyboard();
         }
-        updateShiftState();
     }
 
     public void saveKeyboardState() {
diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardShiftState.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardShiftState.java
index 11fb91a..4608e22 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardShiftState.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardShiftState.java
@@ -73,12 +73,7 @@
                 break;
             }
         } else {
-            switch (oldState) {
-            case SHIFT_LOCKED:
-            case SHIFT_LOCK_SHIFTED:
-                mState = NORMAL;
-                break;
-            }
+            mState = NORMAL;
         }
         if (DEBUG)
             Log.d(TAG, "setShiftLocked(" + newShiftLockState + "): " + toString(oldState)
diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java
index af16e49..babf600 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java
@@ -87,6 +87,16 @@
         public boolean mIsAlphabetMode;
         public boolean mIsShiftLocked;
         public boolean mIsShifted;
+
+        public String toString() {
+            if (!mIsValid) return "INVALID";
+            if (mIsAlphabetMode) {
+                if (mIsShiftLocked) return "ALPHABET_SHIFT_LOCKED";
+                return mIsShifted ? "ALPHABET_SHIFTED" : "ALPHABET";
+            } else {
+                return mIsShifted ? "SYMBOLS_SHIFTED" : "SYMBOLS";
+            }
+        }
     }
 
     public KeyboardState(SwitchActions switchActions) {
@@ -95,7 +105,7 @@
 
     public void onLoadKeyboard(String layoutSwitchBackSymbols) {
         if (DEBUG_EVENT) {
-            Log.d(TAG, "onLoadKeyboard");
+            Log.d(TAG, "onLoadKeyboard: " + this);
         }
         mLayoutSwitchBackSymbols = layoutSwitchBackSymbols;
         // Reset alphabet shift state.
@@ -120,17 +130,14 @@
         }
         state.mIsValid = true;
         if (DEBUG_EVENT) {
-            Log.d(TAG, "onSaveKeyboardState: alphabet=" + state.mIsAlphabetMode
-                    + " shiftLocked=" + state.mIsShiftLocked + " shift=" + state.mIsShifted);
+            Log.d(TAG, "onSaveKeyboardState: saved=" + state + " " + this);
         }
     }
 
     private void onRestoreKeyboardState() {
         final SavedKeyboardState state = mSavedKeyboardState;
         if (DEBUG_EVENT) {
-            Log.d(TAG, "onRestoreKeyboardState: valid=" + state.mIsValid
-                    + " alphabet=" + state.mIsAlphabetMode
-                    + " shiftLocked=" + state.mIsShiftLocked + " shift=" + state.mIsShifted);
+            Log.d(TAG, "onRestoreKeyboardState: saved=" + state + " " + this);
         }
         if (!state.mIsValid || state.mIsAlphabetMode) {
             setAlphabetKeyboard();
diff --git a/java/src/com/android/inputmethod/latin/AutoCorrection.java b/java/src/com/android/inputmethod/latin/AutoCorrection.java
index e5eb159..bcb7891 100644
--- a/java/src/com/android/inputmethod/latin/AutoCorrection.java
+++ b/java/src/com/android/inputmethod/latin/AutoCorrection.java
@@ -74,6 +74,14 @@
         for (final String key : dictionaries.keySet()) {
             if (key.equals(Suggest.DICT_KEY_WHITELIST)) continue;
             final Dictionary dictionary = dictionaries.get(key);
+            // It's unclear how realistically 'dictionary' can be null, but the monkey is somehow
+            // managing to get null in here. Presumably the language is changing to a language with
+            // no main dictionary and the monkey manages to type a whole word before the thread
+            // that reads the dictionary is started or something?
+            // Ideally the passed map would come out of a {@link java.util.concurrent.Future} and
+            // would be immutable once it's finished initializing, but concretely a null test is
+            // probably good enough for the time being.
+            if (null == dictionary) continue;
             if (dictionary.isValidWord(word)
                     || (ignoreCase && dictionary.isValidWord(lowerCasedWord))) {
                 return true;