diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/queue/MessageQueueThreadHandler.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/queue/MessageQueueThreadHandler.java index 010b6871593..ddac0bfec73 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/queue/MessageQueueThreadHandler.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/queue/MessageQueueThreadHandler.java @@ -10,6 +10,8 @@ package com.facebook.react.bridge.queue; import android.os.Handler; import android.os.Looper; import android.os.Message; +import com.facebook.common.logging.FLog; +import com.facebook.react.common.ReactConstants; /** Handler that can catch and dispatch Exceptions to an Exception handler. */ public class MessageQueueThreadHandler extends Handler { @@ -26,6 +28,15 @@ public class MessageQueueThreadHandler extends Handler { try { super.dispatchMessage(msg); } catch (Exception e) { + if (e instanceof NullPointerException) { + FLog.e( + ReactConstants.TAG, + "Caught NullPointerException when dispatching message in MessageQueueThreadHandler. This is likely caused by runnable" + + "(msg.callback) being nulled in Android Handler after dispatching and before handling (see T170239922 for more details)." + + "Currently we observe that it only happen once which is during initialisation. Due to fixing probably involve Android " + + "System code, we decide to ignore here for now and print an error message for debugging purpose in case this cause more serious issues in future."); + return; + } mExceptionHandler.handleException(e); } }