From f1e9c6bde3be5630bf551d3981e9152c617e8163 Mon Sep 17 00:00:00 2001 From: Alex Danoff Date: Thu, 8 Jun 2023 14:33:14 -0700 Subject: [PATCH] W3CPointerEvents: fix NPE due to null targetView Summary: Changelog: [Android] [Fixed] - W3CPointerEvents: fix NPE due to null targetView For reasons not entirely understood, we sometimes end up with a null `targetView` in this code path during the dispatch of an `ACTION_CANCEL`. This results in an NPE during the call to `getChildOffsetRelativeToRoot`. This change adds a null check before the call to avoid the crash. Differential Revision: D46562263 fbshipit-source-id: 65048caa2d49f759ec09799bd7d9209eeb5c60d0 --- .../java/com/facebook/react/uimanager/JSPointerDispatcher.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/JSPointerDispatcher.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/JSPointerDispatcher.java index 0f1a206ba0bfaa..eb970dfbfb443f 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/JSPointerDispatcher.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/JSPointerDispatcher.java @@ -615,7 +615,7 @@ private void dispatchCancelEventForTarget( int activePointerId = eventState.getActivePointerId(); List activeHitPath = eventState.getHitPathByPointerId().get(activePointerId); - if (!activeHitPath.isEmpty()) { + if (!activeHitPath.isEmpty() && targetView != null) { boolean listeningForCancel = isAnyoneListeningForBubblingEvent(activeHitPath, EVENT.CANCEL, EVENT.CANCEL_CAPTURE); if (listeningForCancel) {