From 1a77943e8bef97e7bee903c7bfcf32c56fb8fab8 Mon Sep 17 00:00:00 2001 From: Joshua Gross Date: Tue, 26 May 2020 23:29:06 -0700 Subject: [PATCH] Better error message when crashing because of an invalid Remove operation Summary: Error messages like P131885276 don't help debugging, even when all mount instructions are logged to logcat. This log would help identify the incorrect mount instruction. Changelog: [Internal] Reviewed By: mdvacca Differential Revision: D21735940 fbshipit-source-id: 16ff315c11ccafdd75d0ad9c7c60b7be2cd73202 --- .../react/fabric/mounting/MountingManager.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/MountingManager.java b/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/MountingManager.java index 9388ae6e777..05438adaf07 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/MountingManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/MountingManager.java @@ -242,6 +242,17 @@ public class MountingManager { throw new IllegalStateException("Unable to find view for tag " + parentTag); } + if (parentView.getChildCount() <= index) { + throw new IllegalStateException( + "Cannot remove child at index " + + index + + " from parent ViewGroup [" + + parentView.getId() + + "], only " + + parentView.getChildCount() + + " children in parent"); + } + getViewGroupManager(viewState).removeViewAt(parentView, index); }