Merge "Add a wrapper to updateSuggestions / Predictions (A48)"
diff --git a/java/src/com/android/inputmethod/keyboard/Keyboard.java b/java/src/com/android/inputmethod/keyboard/Keyboard.java
index 1b4cea2..1aec001 100644
--- a/java/src/com/android/inputmethod/keyboard/Keyboard.java
+++ b/java/src/com/android/inputmethod/keyboard/Keyboard.java
@@ -185,19 +185,21 @@
         if (code == CODE_UNSPECIFIED) {
             return null;
         }
-        final int index = mKeyCache.indexOfKey(code);
-        if (index >= 0) {
-            return mKeyCache.valueAt(index);
-        }
-
-        for (final Key key : mKeys) {
-            if (key.mCode == code) {
-                mKeyCache.put(code, key);
-                return key;
+        synchronized (mKeyCache) {
+            final int index = mKeyCache.indexOfKey(code);
+            if (index >= 0) {
+                return mKeyCache.valueAt(index);
             }
+
+            for (final Key key : mKeys) {
+                if (key.mCode == code) {
+                    mKeyCache.put(code, key);
+                    return key;
+                }
+            }
+            mKeyCache.put(code, null);
+            return null;
         }
-        mKeyCache.put(code, null);
-        return null;
     }
 
     public boolean hasKey(Key aKey) {