react-native-onesignal icon indicating copy to clipboard operation
react-native-onesignal copied to clipboard

[Bug]: In-App Messages crash Android devices (fine on iOS) - NullPointerException on HashMap.keySet()

Open VirtualDOMinic opened this issue 2 years ago • 2 comments

What happened?

Recently (but I can't pin down when it started), when testing in-app messages on Android devices, the app crashes and our Sentry reports NullPointerException com.onesignal.OSInAppMessageInternal in toJSONObject, Attempt to invoke virtual method 'java.util.Set java.util.HashMap.keySet()' on a null object reference.

I have yet to test older/newer versions of the library due to time constraints, but I plan to.

image

Steps to reproduce?

1. Build a release version of an app (yet to confirm if bug happens in debug mode on simulator) that uses `react-native-onesignal` v4.5.2
2. Open the app on a real Android device (we've tried on various devices and Android versions, including Galaxy S23 on Android 14, Huawai P30, Galaxy S8 and an older Sony Xperia, all on Android <=13)
3. Accept push notification permissions on the device
4. Add device to test subscriptions in OneSignal dashboard
5. If you like, send a test push notification to confirm they work (they do, no crash)
6. Ensure the app is open on your device, and pen the in-app message editor, create any sort of in-app message and then do "Send Test In-App" from the editor, selecting your Android device
7. The in-app message will cause the app to crash suddenly, within a second or so of the message appearing. Sometimes before the message appeared.

What did you expect to happen?

I expected the in-app message to appear, and to be able to interact with it, dismiss it, or leave it visible, without the app crashing.

React Native OneSignal SDK version

4.5.2

Which platform(s) are affected?

  • [ ] iOS
  • [X] Android

Relevant log output

java.lang.NullPointerException: Attempt to invoke virtual method 'java.util.Set java.util.HashMap.keySet()' on a null object reference
    at com.onesignal.OSInAppMessageInternal.toJSONObject(OSInAppMessageInternal.java:159)
    at com.geektime.rnonesignalandroid.RNOneSignal$13.onWillDisplayInAppMessage(RNOneSignal.java:737)
    at com.onesignal.OSInAppMessageController.onMessageWillDisplay(OSInAppMessageController.java:369)
    at com.onesignal.OSInAppMessageController$14.onSuccess(OSInAppMessageController.java:879)
    at com.onesignal.OSInAppMessageRepository$7.onSuccess(OSInAppMessageRepository.java:142)
    at com.onesignal.OneSignalRestClient$5.run(OneSignalRestClient.java:279)
    at java.lang.Thread.run(Thread.java:929)

Code of Conduct

  • [X] I agree to follow this project's Code of Conduct

VirtualDOMinic avatar Feb 05 '24 14:02 VirtualDOMinic

Currently hypothesising/hoping that this might ONLY happen when sending test messages (step 6 in steps to reproduce) rather than real in-app messages.

And when I look at the code from v4, it seems there is only one HashMap: https://github.com/OneSignal/react-native-onesignal/blob/6d052e92b7cc20bf4c9361688302aa0dac27e556/android/src/main/java/com/geektime/rnonesignalandroid/RNOneSignal.java#L153 -- notificationReceivedEventCache. Maybe there's something not created/handled correctly when a notification is used to trigger a test IAM 🤔

VirtualDOMinic avatar Feb 06 '24 10:02 VirtualDOMinic

Hi, found any solution for this?

nagasailokesh-toddle avatar Aug 06 '24 05:08 nagasailokesh-toddle