diff options
| -rw-r--r-- | core/java/android/view/translation/UiTranslationController.java | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/core/java/android/view/translation/UiTranslationController.java b/core/java/android/view/translation/UiTranslationController.java index a8335918cc84..442d099f0678 100644 --- a/core/java/android/view/translation/UiTranslationController.java +++ b/core/java/android/view/translation/UiTranslationController.java @@ -356,7 +356,11 @@ public class UiTranslationController { } for (int i = 0; i < translatedResult.size(); i++) { final AutofillId autofillId = new AutofillId(translatedResult.keyAt(i)); - final View view = mViews.get(autofillId).get(); + final WeakReference<View> viewRef = mViews.get(autofillId); + if (viewRef == null) { + continue; + } + final View view = viewRef.get(); if (view == null) { Log.w(TAG, "onTranslationCompleted: the view for autofill id " + autofillId + " may be gone."); @@ -416,7 +420,11 @@ public class UiTranslationController { Log.w(TAG, "No AutofillId is set in ViewTranslationResponse"); continue; } - final View view = mViews.get(autofillId).get(); + final WeakReference<View> viewRef = mViews.get(autofillId); + if (viewRef == null) { + continue; + } + final View view = viewRef.get(); if (view == null) { Log.w(TAG, "onTranslationCompleted: the view for autofill id " + autofillId + " may be gone."); |