OneSignal-Android-SDK icon indicating copy to clipboard operation
OneSignal-Android-SDK copied to clipboard

[Bug]: SDK crash on android device | PushRegistrator is null

Open hsaddique opened this issue 1 year ago • 8 comments

What happened?

Fatal Exception: java.lang.NullPointerException: Attempt to invoke interface method 'void com.onesignal.PushRegistrator.registerForPush(android.content.Context, java.lang.String, com.onesignal.PushRegistrator$RegisteredHandler)' on a null object reference at com.onesignal.OneSignal.registerForPushToken(OneSignal.java:1080) at com.onesignal.OneSignal.startRegistrationOrOnSession(OneSignal.java:1030) at com.onesignal.OneSignal.doSessionInit(OneSignal.java:1013) at com.onesignal.OneSignal.init(OneSignal.java:868) at com.onesignal.OneSignal.setAppId(OneSignal.java:737) at com.onesignal.OneSignal.reassignDelayedInitParams(OneSignal.java:1181) at com.onesignal.OneSignal.onRemoteParamSet(OneSignal.java:889) at com.onesignal.OneSignal$7.complete(OneSignal.java:1122) at com.onesignal.OneSignalRemoteParams.processJson(OneSignalRemoteParams.java:211) at com.onesignal.OneSignalRemoteParams.access$100(OneSignalRemoteParams.java:12) at com.onesignal.OneSignalRemoteParams$1.onSuccess(OneSignalRemoteParams.java:156) at com.onesignal.OneSignalRestClient$5.run(OneSignalRestClient.java:279) at java.lang.Thread.run(Thread.java:784)

While investigating the code, the com.onesignal.OneSignal.getPushRegistrator() function has a condition

if (mPushRegistrator != null) { return mPushRegistrator; } else { if (OSUtils.isFireOSDeviceType()) { mPushRegistrator = new PushRegistratorADM(); } else if (OSUtils.isAndroidDeviceType()) { if (OSUtils.hasFCMLibrary()) { mPushRegistrator = getPushRegistratorFCM(); } } else { mPushRegistrator = new PushRegistratorHMS(); }

        return mPushRegistrator;
    }

It is returning the object null if the device is android and it doesn't have the fcm library.

Steps to reproduce?

1. Run the app
2. It will crash while initializing the SDK.

What did you expect to happen?

It should handle the check correctly while identifying device and initializing the SDK correctly

OneSignal Android SDK version

4.8.6

Android version

9, 8

Specific Android models

Honor 8C
Huawei P30 Lite
Galaxy S23 Ultra
Galaxy Tab A

Relevant log output

Fatal Exception: java.lang.NullPointerException: Attempt to invoke interface method 'void com.onesignal.PushRegistrator.registerForPush(android.content.Context, java.lang.String, com.onesignal.PushRegistrator$RegisteredHandler)' on a null object reference
       at com.onesignal.OneSignal.registerForPushToken(OneSignal.java:1080)
       at com.onesignal.OneSignal.startRegistrationOrOnSession(OneSignal.java:1030)
       at com.onesignal.OneSignal.doSessionInit(OneSignal.java:1013)
       at com.onesignal.OneSignal.init(OneSignal.java:868)
       at com.onesignal.OneSignal.setAppId(OneSignal.java:737)
       at com.onesignal.OneSignal.reassignDelayedInitParams(OneSignal.java:1181)
       at com.onesignal.OneSignal.onRemoteParamSet(OneSignal.java:889)
       at com.onesignal.OneSignal$7.complete(OneSignal.java:1122)
       at com.onesignal.OneSignalRemoteParams.processJson(OneSignalRemoteParams.java:211)
       at com.onesignal.OneSignalRemoteParams.access$100(OneSignalRemoteParams.java:12)
       at com.onesignal.OneSignalRemoteParams$1.onSuccess(OneSignalRemoteParams.java:156)
       at com.onesignal.OneSignalRestClient$5.run(OneSignalRestClient.java:279)
       at java.lang.Thread.run(Thread.java:784)

Code of Conduct

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

hsaddique avatar Jun 04 '23 07:06 hsaddique

Hi @hsaddique thanks for reaching out! We'll look into this.

jennantilla avatar Jun 06 '23 17:06 jennantilla

Hi @jennantilla. Any update on this? We are getting a lot of crashes for this in our app.

hsaddique avatar Jun 22 '23 08:06 hsaddique

HI @jennantilla any update?

hsaddique avatar Jul 05 '23 06:07 hsaddique

I'm facing this issue too. @jennantilla any update on this?

iamfazal avatar Aug 26 '23 18:08 iamfazal

@jennantilla it's been more than 6 months, there have been multiple new versions of the SDK, but this error is still not resolved. Can you please update on the resolution time for this? It's just a simple initialization in OneSignal.java class function getPushRegistrator(). private static PushRegistrator mPushRegistrator; this variable is not initialized correctly.

hsaddique avatar Dec 20 '23 06:12 hsaddique

Hello @hsaddique thank you for your patience here. Much of our work in H2 has been on our latest major release where many improvements and enhancements are introduced. We will continue to investigate 4.x.x bugs, though we encourage you to update to 5.1.x as that will be the most-supported release going forward. Please let us know if you have any questions!

jennantilla avatar Dec 28 '23 22:12 jennantilla

Hi @jennantilla can you please confirm if this bug has been fixed in 5.1.x releases?

hsaddique avatar Jan 03 '24 12:01 hsaddique

Hello @hsaddique apologies for the delay in response. I have not seen this issue on 5.1.x.

If you still are experiencing this on the latest version of the SDK, please let us know and we will be happy to dig into it. Thanks!

jennantilla avatar Mar 13 '24 22:03 jennantilla