From 520b662ee5984ae0fe0f4d8649ad095025c776b1 Mon Sep 17 00:00:00 2001 From: Jason Praful Date: Mon, 8 Sep 2025 12:22:38 +0100 Subject: [PATCH] handle null pointer exception in notification handling --- android/src/newarch/IntercomModule.java | 31 +++++++++++++++++++++---- package.json | 2 +- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/android/src/newarch/IntercomModule.java b/android/src/newarch/IntercomModule.java index 3a355b94..8b0edebb 100644 --- a/android/src/newarch/IntercomModule.java +++ b/android/src/newarch/IntercomModule.java @@ -71,7 +71,15 @@ public static boolean isIntercomPush(RemoteMessage remoteMessage) { public static void handleRemotePushWithCustomStack(@NonNull Application application, RemoteMessage remoteMessage, TaskStackBuilder customStack) { try { + if (remoteMessage == null) { + Log.w(NAME, "handleRemotePushWithCustomStack: remoteMessage is null"); + return; + } Map message = remoteMessage.getData(); + if (message == null) { + Log.w(NAME, "handleRemotePushWithCustomStack: message is null"); + return; + } intercomPushClient.handlePushWithCustomStack(application, message, customStack); } catch (Exception err) { Log.e(NAME, "handlePushWithCustomStack error:"); @@ -94,8 +102,17 @@ public static void handleRemotePushMessage(@NonNull Application application, Rem } public static void sendTokenToIntercom(Application application, @NonNull String token) { - intercomPushClient.sendTokenToIntercom(application, token); - Log.d(NAME, "sendTokenToIntercom"); + if (application == null || token == null || token.isEmpty()) { + Log.w(NAME, "sendTokenToIntercom: application or token is null or empty"); + return; + } + try { + intercomPushClient.sendTokenToIntercom(application, token); + Log.d(NAME, "sendTokenToIntercom"); + } catch (Exception err) { + Log.e(NAME, "sendTokenToIntercom error:"); + Log.e(NAME, err.toString()); + } } @ReactMethod @@ -114,14 +131,20 @@ public void handlePushMessage(Promise promise) { @ReactMethod public void sendTokenToIntercom(@NonNull String token, Promise promise) { try { + if (token == null || token.isEmpty()) { + Log.w(NAME, "sendTokenToIntercom: token is null or empty"); + promise.reject(IntercomErrorCodes.SEND_TOKEN_TO_INTERCOM, "token is null or empty"); + return; + } Activity activity = getCurrentActivity(); - if (activity != null) { + if (activity != null && activity.getApplication() != null) { intercomPushClient.sendTokenToIntercom(activity.getApplication(), token); Log.d(NAME, "sendTokenToIntercom"); promise.resolve(true); } else { Log.e(NAME, "sendTokenToIntercom"); Log.e(NAME, "no current activity"); + promise.reject(IntercomErrorCodes.SEND_TOKEN_TO_INTERCOM, "no current activity"); } } catch (Exception err) { @@ -521,7 +544,7 @@ public void setLauncherVisibility(String visibility, Promise promise) { @ReactMethod public void setBottomPadding(double paddingBottom, Promise promise) { try { - Intercom.client().setBottomPadding((int)paddingBottom); + Intercom.client().setBottomPadding((int) paddingBottom); Log.d(NAME, "setBottomPadding"); promise.resolve(true); } catch (Exception err) { diff --git a/package.json b/package.json index c4f2ec6c..f7b6d1b4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@intercom/intercom-react-native", - "version": "9.0.0", + "version": "9.0.1", "description": "React Native wrapper to bridge our iOS and Android SDK", "source": "./src/index.tsx", "main": "./lib/commonjs/index.js",