Fix the NPE on selection string on unlearnWord
Bug: 20150386
Change-Id: I2ed69aba7b1fdaba1e2ac07b8218a265dfe23e09
diff --git a/java/src/com/android/inputmethod/latin/RichInputConnection.java b/java/src/com/android/inputmethod/latin/RichInputConnection.java
index 49c47d7..a123d28 100644
--- a/java/src/com/android/inputmethod/latin/RichInputConnection.java
+++ b/java/src/com/android/inputmethod/latin/RichInputConnection.java
@@ -48,6 +48,7 @@
import com.android.inputmethod.latin.utils.TextRange;
import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
/**
* Enrichment class for InputConnection to simplify interaction and add functionality.
@@ -288,6 +289,7 @@
}
}
+ @Nullable
public CharSequence getSelectedText(final int flags) {
return isConnected() ? mIC.getSelectedText(flags) : null;
}
diff --git a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
index 4bee94a..324ae3a 100644
--- a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
+++ b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
@@ -1089,8 +1089,11 @@
// If there is a selection, remove it.
// We also need to unlearn the selected text.
final CharSequence selection = mConnection.getSelectedText(0 /* 0 for no styles */);
- unlearnWord(selection.toString(), inputTransaction.mSettingsValues,
- Constants.EVENT_BACKSPACE);
+ if (!TextUtils.isEmpty(selection)) {
+ unlearnWord(selection.toString(), inputTransaction.mSettingsValues,
+ Constants.EVENT_BACKSPACE);
+ hasUnlearnedWordBeingDeleted = true;
+ }
final int numCharsDeleted = mConnection.getExpectedSelectionEnd()
- mConnection.getExpectedSelectionStart();
mConnection.setSelection(mConnection.getExpectedSelectionEnd(),