From d6a44e632a7ffbd60b90dac410294947cd82f2d8 Mon Sep 17 00:00:00 2001 From: Pieter De Baets Date: Fri, 1 Mar 2024 03:59:08 -0800 Subject: [PATCH] getChildAtWithSubviewClippingEnabled should be @Nullable Summary: The RemoveDeleteTree operation assumes it can safely call getChildAt with indices that are out of bounds to find all the children. `getChildAtWithSubviewClippingEnabled` was unnecessarily stricter than `getChildAt` and would crash in such cases. Changelog: [Android][Fixed] - Fix crash in `getChildAtWithSubviewClippingEnabled` Reviewed By: NickGerleman Differential Revision: D54380975 fbshipit-source-id: 17e93c685cd07b02dc20efa2fae89090d6e38457 --- .../java/com/facebook/react/views/view/ReactViewGroup.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/view/ReactViewGroup.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/view/ReactViewGroup.java index 793a0f9a584..af5dea7170d 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/view/ReactViewGroup.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/view/ReactViewGroup.java @@ -637,8 +637,11 @@ public class ReactViewGroup extends ViewGroup return mAllChildrenCount; } - /*package*/ View getChildAtWithSubviewClippingEnabled(int index) { - return Assertions.assertNotNull(mAllChildren)[index]; + /*package*/ @Nullable + View getChildAtWithSubviewClippingEnabled(int index) { + return index >= 0 && index < mAllChildrenCount + ? Assertions.assertNotNull(mAllChildren)[index] + : null; } /*package*/ void addViewWithSubviewClippingEnabled(View child, int index) {