From 0ba9808c888a949d08ae01ab26c8a6860fc5fccf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Norte?= Date: Wed, 16 Aug 2023 04:38:47 -0700 Subject: [PATCH] Fix NullPointerException when reporting mounts for mount hooks (#39022) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/39022 Fixes a possible NullPointerException thrown when trying to access the binding after the instance has been destroyed to report mounts. I added a check for the mount item just in case 😅 Changelog: [internal] Reviewed By: lenaic Differential Revision: D48355738 fbshipit-source-id: 401d2e0a52b0764ed89498ecc0176d160226e509 --- .../java/com/facebook/react/fabric/FabricUIManager.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java index bb718fea8a1..90b618e2ed1 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java @@ -1227,20 +1227,21 @@ public class FabricUIManager implements UIManager, LifecycleEventListener { public void run() { mMountNotificationScheduled.set(false); - if (mountItems == null) { + final @Nullable Binding binding = mBinding; + if (mountItems == null || binding == null) { return; } // Collect surface IDs for all the mount items List surfaceIds = new ArrayList(); for (MountItem mountItem : mountItems) { - if (!surfaceIds.contains(mountItem.getSurfaceId())) { + if (mountItem != null && !surfaceIds.contains(mountItem.getSurfaceId())) { surfaceIds.add(mountItem.getSurfaceId()); } } for (int surfaceId : surfaceIds) { - mBinding.reportMount(surfaceId); + binding.reportMount(surfaceId); } } });