From d445b56ce14152b30143302899790af255691148 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Wed, 3 Oct 2012 13:01:52 +0900 Subject: Fix possible NPE caused while monkey test Bug: 7269036 Change-Id: I9054b33ad3c8996cac3ee5f0e9c01ba8ceea4971 --- .../com/android/inputmethod/latin/WordComposer.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'java/src/com/android/inputmethod/latin/WordComposer.java') diff --git a/java/src/com/android/inputmethod/latin/WordComposer.java b/java/src/com/android/inputmethod/latin/WordComposer.java index 8a1bbed12..da0071adc 100644 --- a/java/src/com/android/inputmethod/latin/WordComposer.java +++ b/java/src/com/android/inputmethod/latin/WordComposer.java @@ -177,14 +177,16 @@ public final class WordComposer { * Internal method to retrieve reasonable proximity info for a character. */ private void addKeyInfo(final int codePoint, final Keyboard keyboard) { - final Key key = keyboard.getKey(codePoint); - if (key != null) { - final int x = key.mX + key.mWidth / 2; - final int y = key.mY + key.mHeight / 2; - add(codePoint, x, y); - return; + final int x, y; + final Key key; + if (keyboard != null && (key = keyboard.getKey(codePoint)) != null) { + x = key.mX + key.mWidth / 2; + y = key.mY + key.mHeight / 2; + } else { + x = Constants.NOT_A_COORDINATE; + y = Constants.NOT_A_COORDINATE; } - add(codePoint, Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE); + add(codePoint, x, y); } /** @@ -195,7 +197,7 @@ public final class WordComposer { reset(); final int length = word.length(); for (int i = 0; i < length; i = Character.offsetByCodePoints(word, i, 1)) { - int codePoint = Character.codePointAt(word, i); + final int codePoint = Character.codePointAt(word, i); addKeyInfo(codePoint, keyboard); } mIsResumed = true; -- cgit v1.2.3-83-g751a