Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
1 task done
hsaddique opened this issue Jun 4, 2023 · 9 comments
Closed
1 task done

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

hsaddique opened this issue Jun 4, 2023 · 9 comments

Comments

@hsaddique
Copy link

hsaddique commented Jun 4, 2023

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

  • I agree to follow this project's Code of Conduct
@jennantilla
Copy link
Contributor

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

@hsaddique
Copy link
Author

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

@hsaddique
Copy link
Author

HI @jennantilla any update?

@iamfazal
Copy link

iamfazal commented Aug 26, 2023

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

@hsaddique
Copy link
Author

@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.

@jennantilla
Copy link
Contributor

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!

@hsaddique
Copy link
Author

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

@jennantilla
Copy link
Contributor

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!

@jkasten2
Copy link
Member

jkasten2 commented Nov 1, 2024

@jkasten2 jkasten2 closed this as completed Nov 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants