From de12c1bf49efb6ac9b7127933eebb08956488ace Mon Sep 17 00:00:00 2001 From: Yohei Yukawa Date: Mon, 29 Sep 2014 16:17:52 +0900 Subject: [PATCH] Fix NPE due to the lack of null-check The case that was not coverted well is that CursorAnchorInfoCompatWrapper could be instantiated with null object. In such situations, we should do nothing. BUG: 17682582 Change-Id: I6625a2f0ed8c5580ed9edfe4728f342da77a8e40 --- .../inputmethod/compat/CursorAnchorInfoCompatWrapper.java | 6 +++--- .../src/com/android/inputmethod/keyboard/TextDecorator.java | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/java/src/com/android/inputmethod/compat/CursorAnchorInfoCompatWrapper.java b/java/src/com/android/inputmethod/compat/CursorAnchorInfoCompatWrapper.java index c937eeeaa..5af31795c 100644 --- a/java/src/com/android/inputmethod/compat/CursorAnchorInfoCompatWrapper.java +++ b/java/src/com/android/inputmethod/compat/CursorAnchorInfoCompatWrapper.java @@ -84,8 +84,8 @@ public final class CursorAnchorInfoCompatWrapper { } @UsedForTesting - public static boolean isAvailable() { - return sCursorAnchorInfoClass.exists(); + public boolean isAvailable() { + return sCursorAnchorInfoClass.exists() && mInstance != null; } private Object mInstance; @@ -96,7 +96,7 @@ public final class CursorAnchorInfoCompatWrapper { @UsedForTesting public static CursorAnchorInfoCompatWrapper fromObject(final Object instance) { - if (!isAvailable()) { + if (!sCursorAnchorInfoClass.exists()) { return new CursorAnchorInfoCompatWrapper(null); } return new CursorAnchorInfoCompatWrapper(instance); diff --git a/java/src/com/android/inputmethod/keyboard/TextDecorator.java b/java/src/com/android/inputmethod/keyboard/TextDecorator.java index 6e4e3281e..c22717f95 100644 --- a/java/src/com/android/inputmethod/keyboard/TextDecorator.java +++ b/java/src/com/android/inputmethod/keyboard/TextDecorator.java @@ -182,7 +182,7 @@ public class TextDecorator { private void layoutMain() { final CursorAnchorInfoCompatWrapper info = mCursorAnchorInfoWrapper; - if (info == null) { + if (info == null || !info.isAvailable()) { cancelLayoutInternalExpectedly("CursorAnchorInfo isn't available."); return; }