From f26fb3097a69710c9e0d608b5c5612c43dc01c7c Mon Sep 17 00:00:00 2001 From: Holly Sun Date: Thu, 14 Mar 2024 16:20:32 -0700 Subject: [PATCH] [PS] Return earlier if the input is null for `matches`. In test environment, we get null string from resource, so just bypass this part. Bug: 329442658 Test: manual Flag: aconfig com.google.android.apps.nexuslauncher.enable_inject_private_space_tile trunkfood Change-Id: If20586bcd882d6a705e8a670bc20a5cf5aa79ac2 --- .../android/launcher3/search/StringMatcherUtility.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/com/android/launcher3/search/StringMatcherUtility.java b/src/com/android/launcher3/search/StringMatcherUtility.java index 28fc4f002b..7446314296 100644 --- a/src/com/android/launcher3/search/StringMatcherUtility.java +++ b/src/com/android/launcher3/search/StringMatcherUtility.java @@ -18,6 +18,8 @@ package com.android.launcher3.search; import android.text.TextUtils; +import androidx.annotation.Nullable; + import com.android.launcher3.util.IntArray; import java.text.Collator; @@ -120,7 +122,11 @@ public class StringMatcherUtility { /** * Returns true if {@param query} is a prefix of {@param target} */ - public boolean matches(String query, String target) { + public boolean matches(@Nullable String query, @Nullable String target) { + // `mCollator.compare` requires non-null inputs, so return false earlier (not a match) + if (query == null || target == null) { + return false; + } switch (mCollator.compare(query, target)) { case 0: return true;