From 1127895fd42111f95fdc5049141c512e60198292 Mon Sep 17 00:00:00 2001 From: Eric Fischer Date: Mon, 8 Mar 2010 16:38:03 -0800 Subject: [PATCH] Guard against calls to getTextAfterCursor() in text that has no cursor. Act like the cursor is at 0 in this case instead of crashing. Bug 2497485 Change-Id: I5ce9b83b323d895e3be75e3133ff2f8e33cc203d --- core/java/android/view/inputmethod/BaseInputConnection.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/core/java/android/view/inputmethod/BaseInputConnection.java b/core/java/android/view/inputmethod/BaseInputConnection.java index 739373792047b..6ac16338f6d29 100644 --- a/core/java/android/view/inputmethod/BaseInputConnection.java +++ b/core/java/android/view/inputmethod/BaseInputConnection.java @@ -328,6 +328,11 @@ public class BaseInputConnection implements InputConnection { b = tmp; } + // Guard against the case where the cursor has not been positioned yet. + if (b < 0) { + b = 0; + } + if (b + length > content.length()) { length = content.length() - b; }