Merge "[TestPrep3] Add helper method to retrive dictionary"
diff --git a/java/src/com/android/inputmethod/research/MainLogBuffer.java b/java/src/com/android/inputmethod/research/MainLogBuffer.java
index 3a87bf1..182b924 100644
--- a/java/src/com/android/inputmethod/research/MainLogBuffer.java
+++ b/java/src/com/android/inputmethod/research/MainLogBuffer.java
@@ -93,6 +93,11 @@
         mSuggest = suggest;
     }
 
+    private Dictionary getDictionary() {
+        if (mSuggest == null || !mSuggest.hasMainDictionary()) return null;
+        return mSuggest.getMainDictionary();
+    }
+
     public void resetWordCounter() {
         mNumWordsUntilSafeToSample = mNumWordsBetweenNGrams;
     }
@@ -137,18 +142,15 @@
         if (mNumWordsUntilSafeToSample > 0) {
             return false;
         }
-        if (mSuggest == null || !mSuggest.hasMainDictionary()) {
+        // Reload the dictionary in case it has changed (e.g., because the user has changed
+        // languages).
+        final Dictionary dictionary = getDictionary();
+        if (dictionary == null) {
             // Main dictionary is unavailable.  Since we cannot check it, we cannot tell if a
             // word is out-of-vocabulary or not.  Therefore, we must judge the entire buffer
             // contents to potentially pose a privacy risk.
             return false;
         }
-        // Reload the dictionary in case it has changed (e.g., because the user has changed
-        // languages).
-        final Dictionary dictionary = mSuggest.getMainDictionary();
-        if (dictionary == null) {
-            return false;
-        }
 
         // Check each word in the buffer.  If any word poses a privacy threat, we cannot upload
         // the complete buffer contents in detail.