From d1a8e3088bb6267a31e3351d304796d1507e3af6 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Thu, 23 Sep 2010 12:31:22 +0900 Subject: [PATCH] Fix ArrayIndexOutOfBoundsException in WordComposer Bug: 3028277 Change-Id: I1c4d8dca4db8a70f851589d1fbd45a16ea1bfc1b --- .../inputmethod/latin/WordComposer.java | 26 +++++++------------ 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/java/src/com/android/inputmethod/latin/WordComposer.java b/java/src/com/android/inputmethod/latin/WordComposer.java index 6772d53ea..fe4c68576 100644 --- a/java/src/com/android/inputmethod/latin/WordComposer.java +++ b/java/src/com/android/inputmethod/latin/WordComposer.java @@ -25,14 +25,14 @@ public class WordComposer { /** * The list of unicode values for each keystroke (including surrounding keys) */ - private ArrayList mCodes; + private final ArrayList mCodes; /** * The word chosen from the candidate list, until it is committed. */ private String mPreferredWord; - private StringBuilder mTypedWord; + private final StringBuilder mTypedWord; private int mCapsCount; @@ -116,11 +116,14 @@ public class WordComposer { * Delete the last keystroke as a result of hitting backspace. */ public void deleteLast() { - mCodes.remove(mCodes.size() - 1); - final int lastPos = mTypedWord.length() - 1; - char last = mTypedWord.charAt(lastPos); - mTypedWord.deleteCharAt(lastPos); - if (Character.isUpperCase(last)) mCapsCount--; + final int codesSize = mCodes.size(); + if (codesSize > 0) { + mCodes.remove(codesSize - 1); + final int lastPos = mTypedWord.length() - 1; + char last = mTypedWord.charAt(lastPos); + mTypedWord.deleteCharAt(lastPos); + if (Character.isUpperCase(last)) mCapsCount--; + } } /** @@ -132,15 +135,6 @@ public class WordComposer { if (wordSize == 0) { return null; } -// StringBuffer sb = new StringBuffer(wordSize); -// for (int i = 0; i < wordSize; i++) { -// char c = (char) mCodes.get(i)[0]; -// if (i == 0 && mIsCapitalized) { -// c = Character.toUpperCase(c); -// } -// sb.append(c); -// } -// return sb; return mTypedWord; }