Skip to content

Commit 520b662

Browse files
committed
handle null pointer exception in notification handling
1 parent c662ad4 commit 520b662

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

android/src/newarch/IntercomModule.java

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,15 @@ public static boolean isIntercomPush(RemoteMessage remoteMessage) {
7171
public static void handleRemotePushWithCustomStack(@NonNull Application application, RemoteMessage remoteMessage,
7272
TaskStackBuilder customStack) {
7373
try {
74+
if (remoteMessage == null) {
75+
Log.w(NAME, "handleRemotePushWithCustomStack: remoteMessage is null");
76+
return;
77+
}
7478
Map<String, String> message = remoteMessage.getData();
79+
if (message == null) {
80+
Log.w(NAME, "handleRemotePushWithCustomStack: message is null");
81+
return;
82+
}
7583
intercomPushClient.handlePushWithCustomStack(application, message, customStack);
7684
} catch (Exception err) {
7785
Log.e(NAME, "handlePushWithCustomStack error:");
@@ -94,8 +102,17 @@ public static void handleRemotePushMessage(@NonNull Application application, Rem
94102
}
95103

96104
public static void sendTokenToIntercom(Application application, @NonNull String token) {
97-
intercomPushClient.sendTokenToIntercom(application, token);
98-
Log.d(NAME, "sendTokenToIntercom");
105+
if (application == null || token == null || token.isEmpty()) {
106+
Log.w(NAME, "sendTokenToIntercom: application or token is null or empty");
107+
return;
108+
}
109+
try {
110+
intercomPushClient.sendTokenToIntercom(application, token);
111+
Log.d(NAME, "sendTokenToIntercom");
112+
} catch (Exception err) {
113+
Log.e(NAME, "sendTokenToIntercom error:");
114+
Log.e(NAME, err.toString());
115+
}
99116
}
100117

101118
@ReactMethod
@@ -114,14 +131,20 @@ public void handlePushMessage(Promise promise) {
114131
@ReactMethod
115132
public void sendTokenToIntercom(@NonNull String token, Promise promise) {
116133
try {
134+
if (token == null || token.isEmpty()) {
135+
Log.w(NAME, "sendTokenToIntercom: token is null or empty");
136+
promise.reject(IntercomErrorCodes.SEND_TOKEN_TO_INTERCOM, "token is null or empty");
137+
return;
138+
}
117139
Activity activity = getCurrentActivity();
118-
if (activity != null) {
140+
if (activity != null && activity.getApplication() != null) {
119141
intercomPushClient.sendTokenToIntercom(activity.getApplication(), token);
120142
Log.d(NAME, "sendTokenToIntercom");
121143
promise.resolve(true);
122144
} else {
123145
Log.e(NAME, "sendTokenToIntercom");
124146
Log.e(NAME, "no current activity");
147+
promise.reject(IntercomErrorCodes.SEND_TOKEN_TO_INTERCOM, "no current activity");
125148
}
126149

127150
} catch (Exception err) {
@@ -521,7 +544,7 @@ public void setLauncherVisibility(String visibility, Promise promise) {
521544
@ReactMethod
522545
public void setBottomPadding(double paddingBottom, Promise promise) {
523546
try {
524-
Intercom.client().setBottomPadding((int)paddingBottom);
547+
Intercom.client().setBottomPadding((int) paddingBottom);
525548
Log.d(NAME, "setBottomPadding");
526549
promise.resolve(true);
527550
} catch (Exception err) {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@intercom/intercom-react-native",
3-
"version": "9.0.0",
3+
"version": "9.0.1",
44
"description": "React Native wrapper to bridge our iOS and Android SDK",
55
"source": "./src/index.tsx",
66
"main": "./lib/commonjs/index.js",

0 commit comments

Comments
 (0)