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

[Bug]: OneSignalService.onPostAppCreated java.lang.NullPointerException

Open albertoderodrigo opened this issue 1 year ago • 9 comments

What happened?

Since que upgraded from OneSignal 4.X.X to OneSignal 5.0.4 we started to see the following error on Firebase crashlytics.

Caused by java.lang.NullPointerException: at com.onesignal.core.internal.application.impl.ApplicationService.getAppContext(ApplicationService.kt:39) at com.onesignal.core.internal.preferences.impl.PreferencesService.getSharedPrefsByName(PreferencesService.kt:234) at com.onesignal.core.internal.preferences.impl.PreferencesService.get(PreferencesService.kt:134) at com.onesignal.core.internal.preferences.impl.PreferencesService.getString(PreferencesService.kt:42) at com.onesignal.common.modeling.ModelStore.load(ModelStore.kt:165) at com.onesignal.common.modeling.SimpleModelStore.(SimpleModelStore.kt:23) at com.onesignal.core.internal.config.ConfigModelStore.(ConfigModelStore.kt:8) at java.lang.reflect.Constructor.newInstance0(Constructor.java) at java.lang.reflect.Constructor.newInstance(Constructor.java:343) at com.onesignal.common.services.ServiceRegistrationReflection.resolve(ServiceRegistration.kt:89) at com.onesignal.common.services.ServiceProvider.getServiceOrNull(ServiceProvider.kt:79) at com.onesignal.common.services.ServiceProvider.getService(ServiceProvider.kt:67) at com.onesignal.common.services.ServiceProvider.getService$com_onesignal_core(ServiceProvider.kt:39) at com.onesignal.internal.OneSignalImp.initWithContext(OneSignalImp.kt:188) at com.onesignal.OneSignal.initWithContext(OneSignal.kt:135)

Full Log

This happens on the start up and in a variety of devices and Android Versions.

Screenshot 2023-11-20 at 09 05 09

Steps to reproduce?

Upgrade to OneSignal 5.0.4 aande wait for the errors on Firebase crashlytics.

We didn't find a way to reproduce it in our test devices.

What did you expect to happen?

No errors on FIrebase crashlytics

OneSignal Android SDK version

5.0.4

Android version

13, 12, 11, 10, 9

Specific Android models

No response

Relevant log output

No response

Code of Conduct

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

albertoderodrigo avatar Nov 20 '23 08:11 albertoderodrigo

Thank you for reaching out! We'll investigate this.

jennantilla avatar Nov 20 '23 21:11 jennantilla

Hi we just updated to the latest of the sdk 5.0.5 and the problem remains.

Screenshot 2023-12-14 at 09 36 28

this is a fresh log

io.socialgamesonline.slotcom_issue_b195941da1928b51d7cb0e43076dd8dc_crash_session_657A7843002D00017F30B9EF82B82DED_DNE_0_v2_stacktrace (1).txt

albertoderodrigo avatar Dec 14 '23 08:12 albertoderodrigo

Hello just for your info we just updated to the latest versión 5.1.0 and the error remains.

io.socialgamesonline.slotcom_issue_b195941da1928b51d7cb0e43076dd8dc_crash_session_6595FBD7003100011A74FA3E34186E71_DNE_0_v2_stacktrace.txt

This is the top error in our app :(

Screenshot 2024-01-04 at 08 35 38

albertoderodrigo avatar Jan 04 '24 07:01 albertoderodrigo

Hello we released a new version with the 5.1.1 and the error persists (But we reduced ARN thx!).

This is a log with the last version

io.socialgamesonline.slotcom_issue_b195941da1928b51d7cb0e43076dd8dc_crash_session_65B0A5B7008E00012846EADB61154D90_DNE_0_v2_stacktrace.txt

Can you give me some feedback @jennantilla please is the most frequent error on our app.

Regards

albertoderodrigo avatar Jan 24 '24 07:01 albertoderodrigo

Hello? any news regarding this @jennantilla.

albertoderodrigo avatar Jan 29 '24 07:01 albertoderodrigo

Hi @albertoderodrigo, Thank you for following up with your updates and attaching new stacktraces.

I am noting for ourselves to investigate that the stacktraces show two scenarios that triggered the getAppContext NPE:

com.onesignal.core.internal.preferences.impl.PreferencesService.getSharedPrefsByName(PreferencesService.kt:234)
com.onesignal.core.internal.device.impl.DeviceService.packageInstalledAndEnabled(DeviceService.kt:106)

We have no updates yet.

nan-li avatar Feb 02 '24 18:02 nan-li

Hi @nan-li,

We can add more logs or traces at the moment that the exception is raised. What information could help you?

albertoderodrigo avatar Feb 06 '24 12:02 albertoderodrigo

Hi @albertoderodrigo,

I have looked at your logs again, and they all arise from your app's method onPostAppCreated calling OneSignal.initWithContext. Can you share what kind of context you are passing?

       at com.onesignal.OneSignal.initWithContext(OneSignal.kt:135)
       at io.socialgamesonline.slotcom.features.OneSignalService.onPostAppCreated(OneSignalService.kt:38)

Also, do you see any crashes that originate from other sources that are not from you calilng the method, such as BroadcastReceivers, etc?

nan-li avatar Feb 20 '24 20:02 nan-li

Hi @nan-li.

We use the getApplicationContext from the custom Application. This is provided on the onCreate event.

Screenshot 2024-02-23 at 14 55 23

I just checked a lot of this crashes an all are originated from the same source. Has your initWithContext checks if context is null then the only possibility that i see is that sometimes ApplicationService init has not been called before the trying to acquire the context from it.

albertoderodrigo avatar Feb 23 '24 14:02 albertoderodrigo

We have a fix that will lower and possibly fix all crashes related to this null Context being thrown from initWithContext issue in the OneSignal-Android-SDK 5.1.6 release.

@albertoderodrigo if you continue to seeing this issue after updating to 5.1.6 please let us know the new percentages of crashes the new stack traces.

jkasten2 avatar Mar 02 '24 03:03 jkasten2

Hi @jkasten2, we just releases a hotfix with your update. On Monday I will let you know if it has disappeared or not.

Thx

albertoderodrigo avatar Mar 02 '24 12:03 albertoderodrigo

Hi @jkasten2, the error disappeared!! Thx!

albertoderodrigo avatar Mar 04 '24 12:03 albertoderodrigo

@albertoderodrigo That is awesome to hear! Appreciate you reporting back the results!

jkasten2 avatar Mar 04 '24 21:03 jkasten2