From 998a2bbbb59ebc86d1b5ff3d3543cec87f87961c Mon Sep 17 00:00:00 2001 From: zhuning3 Date: Mon, 22 Apr 2024 14:49:35 +0800 Subject: Fix nullptr exception when using do-while Using of 'instanceof' cannot determine whether 'nextParent' is non-null during the first loop in do-while, so when 'focused.getParent()' outside the loop returns null, the loop body will trigger a null pointer exception. Therefore, the conditional judgment needs to be covered in every loop. Test:UAT Bug: 336205346 Change-Id: I78374410d928009ea9b99630cae2fbea24ba8ab6 Signed-off-by: zhuning3 --- core/java/android/view/FocusFinder.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/java/android/view/FocusFinder.java b/core/java/android/view/FocusFinder.java index 064bc6947fc4..5c49e24439bb 100644 --- a/core/java/android/view/FocusFinder.java +++ b/core/java/android/view/FocusFinder.java @@ -129,7 +129,7 @@ public class FocusFinder { } ViewGroup effective = null; ViewParent nextParent = focused.getParent(); - do { + while (nextParent instanceof ViewGroup) { if (nextParent == root) { return effective != null ? effective : root; } @@ -143,7 +143,7 @@ public class FocusFinder { effective = vg; } nextParent = nextParent.getParent(); - } while (nextParent instanceof ViewGroup); + } return root; } -- cgit v1.2.3-59-g8ed1b