From 5f0a5eb87782432dbec3fbd04ff2dd373b2bc88b Mon Sep 17 00:00:00 2001 From: Andy Wickham Date: Tue, 18 Jan 2022 09:13:43 -0800 Subject: [PATCH] Utilities.trim never returns null. This fixes a crash loop I was seeing on my device and also preemptively fixes similar NullPointerExceptions. Bug: 213931730 Test: Manually verified crash loop stopped with this change. Change-Id: I8d2fc8475d42ac60b7fdc9219421a8c9733c7b9f (cherry picked from commit 56be73be80a81df05e34999c42df9203c276b0af) --- src/com/android/launcher3/BubbleTextView.java | 3 ++- src/com/android/launcher3/Utilities.java | 3 ++- src/com/android/launcher3/model/LoaderCursor.java | 3 +-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/com/android/launcher3/BubbleTextView.java b/src/com/android/launcher3/BubbleTextView.java index 1f1d57adc9..163b442b6e 100644 --- a/src/com/android/launcher3/BubbleTextView.java +++ b/src/com/android/launcher3/BubbleTextView.java @@ -35,6 +35,7 @@ import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; import android.icu.text.MessageFormat; import android.text.TextPaint; +import android.text.TextUtils; import android.text.TextUtils.TruncateAt; import android.util.AttributeSet; import android.util.Property; @@ -785,7 +786,7 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver, invalidate(); } } - if (itemInfo.contentDescription != null) { + if (!TextUtils.isEmpty(itemInfo.contentDescription)) { if (itemInfo.isDisabled()) { setContentDescription(getContext().getString(R.string.disabled_app_label, itemInfo.contentDescription)); diff --git a/src/com/android/launcher3/Utilities.java b/src/com/android/launcher3/Utilities.java index d2fe483c96..63313f770f 100644 --- a/src/com/android/launcher3/Utilities.java +++ b/src/com/android/launcher3/Utilities.java @@ -460,9 +460,10 @@ public final class Utilities { * Trims the string, removing all whitespace at the beginning and end of the string. * Non-breaking whitespaces are also removed. */ + @NonNull public static String trim(CharSequence s) { if (s == null) { - return null; + return ""; } // Just strip any sequence of whitespace or java space characters from the beginning and end diff --git a/src/com/android/launcher3/model/LoaderCursor.java b/src/com/android/launcher3/model/LoaderCursor.java index 08b38e88ac..178fbdb7b8 100644 --- a/src/com/android/launcher3/model/LoaderCursor.java +++ b/src/com/android/launcher3/model/LoaderCursor.java @@ -202,8 +202,7 @@ public class LoaderCursor extends CursorWrapper { * Returns the title or empty string */ private String getTitle() { - String title = getString(titleIndex); - return TextUtils.isEmpty(title) ? "" : Utilities.trim(title); + return Utilities.trim(getString(titleIndex)); } /**