Skip to content

Commit 574d3f3

Browse files
CarlyHarlyDanielEliraz
authored andcommitted
Avoid undefined payloads
* Avoid undefined payloads * Check for null instead of relying on try/catch * Remove redundant null check * Wrap in try/catch instead of null checks
1 parent 102d64f commit 574d3f3

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

lib/android/app/src/main/java/com/wix/reactnativenotifications/core/notification/PushNotification.java

+18-4
Original file line numberDiff line numberDiff line change
@@ -198,18 +198,32 @@ protected int createNotificationId(Notification notification) {
198198
}
199199

200200
private void notifyReceivedToJS() {
201-
mJsIOHelper.sendEventToJS(NOTIFICATION_RECEIVED_EVENT_NAME, mNotificationProps.asBundle(), mAppLifecycleFacade.getRunningReactContext());
201+
try {
202+
Bundle bundle = mNotificationProps.asBundle();
203+
mJsIOHelper.sendEventToJS(NOTIFICATION_RECEIVED_EVENT_NAME, bundle, mAppLifecycleFacade.getRunningReactContext());
204+
} catch (NullPointerException ex) {
205+
Log.e(LOGTAG, "notifyReceivedToJS: Null pointer exception");
206+
}
202207
}
203208

204209
private void notifyReceivedBackgroundToJS() {
205-
mJsIOHelper.sendEventToJS(NOTIFICATION_RECEIVED_BACKGROUND_EVENT_NAME, mNotificationProps.asBundle(), mAppLifecycleFacade.getRunningReactContext());
210+
try {
211+
Bundle bundle = mNotificationProps.asBundle();
212+
mJsIOHelper.sendEventToJS(NOTIFICATION_RECEIVED_BACKGROUND_EVENT_NAME, bundle, mAppLifecycleFacade.getRunningReactContext());
213+
} catch (NullPointerException ex) {
214+
Log.e(LOGTAG, "notifyReceivedBackgroundToJS: Null pointer exception");
215+
}
206216
}
207217

208218
private void notifyOpenedToJS() {
209219
Bundle response = new Bundle();
210-
response.putBundle("notification", mNotificationProps.asBundle());
211220

212-
mJsIOHelper.sendEventToJS(NOTIFICATION_OPENED_EVENT_NAME, response, mAppLifecycleFacade.getRunningReactContext());
221+
try {
222+
response.putBundle("notification", mNotificationProps.asBundle());
223+
mJsIOHelper.sendEventToJS(NOTIFICATION_OPENED_EVENT_NAME, response, mAppLifecycleFacade.getRunningReactContext());
224+
} catch (NullPointerException ex) {
225+
Log.e(LOGTAG, "notifyOpenedToJS: Null pointer exception");
226+
}
213227
}
214228

215229
protected void launchOrResumeApp() {

0 commit comments

Comments
 (0)