From 7ebd5f7c3b7d85298c3f9fd384c97ee4b8eb9627 Mon Sep 17 00:00:00 2001 From: Joanne Chung Date: Thu, 9 Dec 2021 14:12:59 +0800 Subject: [PATCH] Fix NPE if no AutofillId when traversing the view tree. Bug: 415172066 Test: atest CtsTranslationTestCases Change-Id: Ic4d7fac7348199d4752c622036d6b57c186816e5 --- core/java/android/view/translation/UiTranslationController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/java/android/view/translation/UiTranslationController.java b/core/java/android/view/translation/UiTranslationController.java index 357dbc0d1f064..8532763f9dada 100644 --- a/core/java/android/view/translation/UiTranslationController.java +++ b/core/java/android/view/translation/UiTranslationController.java @@ -623,7 +623,7 @@ public class UiTranslationController { private void addViewIfNeeded(IntArray sourceViewIds, View view) { final AutofillId autofillId = view.getAutofillId(); - if ((sourceViewIds.indexOf(autofillId.getViewId()) >= 0) + if (autofillId != null && (sourceViewIds.indexOf(autofillId.getViewId()) >= 0) && !mViews.containsKey(autofillId)) { mViews.put(autofillId, new WeakReference<>(view)); }