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]: 5.1.4 - NullPointerException: null cannot be cast to non-null type kotlin.String crashes on Startup #1995

Closed
1 task done
CarlBarks opened this issue Feb 15, 2024 · 6 comments
Labels

Comments

@CarlBarks
Copy link

CarlBarks commented Feb 15, 2024

What happened?

We experienced a NullPointer on initialisation which causes the app to crash on startup. We are on 5.1.4

Might be related to #1990 but the logoutput there suggests a crash at a different place

Seems more related to #1745 however, that was closed in March 2023.

Steps to reproduce?

Not easily reproducible 

1. OneSignal Android SDK `5.1.4`
2. `initWithContext` 
3. Experience crash on Crashlytics

What did you expect to happen?

OneSignal to get initialised without issues across all users and devices

OneSignal Android SDK version

5.1.4

Android version

9

Specific Android models

No response

Relevant log output

Fatal Exception: java.lang.RuntimeException
Unable to create application xxx: java.lang.NullPointerException: null cannot be cast to non-null type kotlin.String
Caused by java.lang.NullPointerException
null cannot be cast to non-null type kotlin.String
com.onesignal.common.modeling.Model.getStringProperty (Model.kt:491)
com.onesignal.common.modeling.Model.getStringProperty$default (Model.kt:488)
com.onesignal.user.internal.identity.IdentityModel.getOnesignalId (IdentityModel.kt:19)
com.onesignal.user.internal.operations.impl.listeners.SubscriptionModelStoreListener.getUpdateOperation (SubscriptionModelStoreListener.kt:48)
com.onesignal.user.internal.operations.impl.listeners.SubscriptionModelStoreListener.getUpdateOperation (SubscriptionModelStoreListener.kt:15)
com.onesignal.core.internal.operations.listeners.ModelStoreListener.onModelUpdated (ModelStoreListener.kt:52)
com.onesignal.common.modeling.ModelStore$onChanged$1.invoke (ModelStore.kt:91)
com.onesignal.common.modeling.ModelStore$onChanged$1.invoke (ModelStore.kt:91)
com.onesignal.common.events.EventProducer.fire (EventProducer.kt:50)
com.onesignal.common.modeling.ModelStore.onChanged (ModelStore.kt:91)
com.onesignal.common.modeling.Model$notifyChanged$1.invoke (Model.kt:666)
com.onesignal.common.modeling.Model$notifyChanged$1.invoke (Model.kt:666)
com.onesignal.common.events.EventProducer.fire (EventProducer.kt:50)
com.onesignal.common.modeling.Model.notifyChanged (Model.kt:666)
com.onesignal.common.modeling.Model.setOptAnyProperty (Model.kt:460)
com.onesignal.common.modeling.Model.setOptEnumProperty$default (Model.kt:327)
com.onesignal.user.internal.subscriptions.SubscriptionModel.getStatus (SubscriptionModel.kt:117)
com.onesignal.user.internal.PushSubscription.getOptedIn (PushSubscription.kt:22)
com.onesignal.user.internal.PushSubscription.fetchState (PushSubscription.kt:44)
com.onesignal.user.internal.PushSubscription.<init> (PushSubscription.kt:15)
com.onesignal.user.internal.subscriptions.impl.SubscriptionManager.createSubscriptionFromModel (SubscriptionManager.kt:232)
com.onesignal.user.internal.subscriptions.impl.SubscriptionManager.createSubscriptionAndAddToSubscriptionList (SubscriptionManager.kt)
com.onesignal.user.internal.subscriptions.impl.SubscriptionManager.onModelAdded (SubscriptionManager.kt:149)
com.onesignal.user.internal.subscriptions.impl.SubscriptionManager.onModelRemoved (SubscriptionManager.kt:41)
com.onesignal.user.internal.subscriptions.impl.SubscriptionManager.onModelAdded (SubscriptionManager.kt:41)
com.onesignal.common.modeling.ModelStore$addItem$2.invoke (ModelStore.kt:138)
com.onesignal.common.modeling.ModelStore$addItem$2.invoke (ModelStore.kt:138)
com.onesignal.common.events.EventProducer.fire (EventProducer.kt:50)
com.onesignal.common.modeling.ModelStore.addItem (ModelStore.kt:138)
com.onesignal.common.modeling.ModelStore.addItem$default (ModelStore.kt:121)
com.onesignal.common.modeling.ModelStore.add (ModelStore.kt:49)
com.onesignal.internal.OneSignalImp.initWithContext (OneSignalImp.kt:299)
com.onesignal.OneSignal.initWithContext (OneSignal.kt:135)
xxx.onCreate (CustomApplication.kt:40)
android.app.Instrumentation.callApplicationOnCreate (Instrumentation.java:1154)

Code of Conduct

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

Hello @CarlBarks, thanks for sharing the stack trace. Could you provide a little more info with any event listener or observer that you have added under OneSignal?

From the look of the stack trace you were trying to access onesignalId in one of the event handler. Note that onesignalId isn't always available. If that is the case, I would recommend using OneSignal.getUser().addObserver to get the IDs when they are available.

@CarlBarks
Copy link
Author

Hi @jinliu9508 , we are not trying to retrieve the oneSignalId anywhere.

The only place where we are using it and we are seeing the crash, is when initialising OneSignal with OneSignal.initWithContext(this, getString(R.string.one_signal_app_id))

The only observer we have is the following:
OneSignal.Notifications.addPermissionObserver(this)

Where no onesignalId is used or retrieved.

@CarlBarks
Copy link
Author

@jinliu9508 and OneSignal team.

We got 18 more crashes in this issue today.
An interesting information for you is that 100% of the crashes happen on Samsung Model:Galaxy S7 on Android 8.0.0.

We would highly appreciate if you could look into this issue in one of your upcoming releases.

@jinliu9508
Copy link
Contributor

@jinliu9508 and OneSignal team.

We got 18 more crashes in this issue today. An interesting information for you is that 100% of the crashes happen on Samsung Model:Galaxy S7 on Android 8.0.0.

We would highly appreciate if you could look into this issue in one of your upcoming releases.

@CarlBarks Thanks for the additional info! The team is currently looking into this bug and it is determined that this issue is caused by the migration from v4 to v5. We will keep you posted once an update is out.

@alenjularic
Copy link

alenjularic commented Feb 28, 2024

Hello, got the same identical crashes (lots of them) on 1S SDK 5.1.4, on all sorts of devices and OS versions.
We do access onesignalId after we initWithContext. If you need any additional info, please do tell and I'll try to provide it.

OneSignal.initWithContext(this, getString(R.string.onesignal_id))
val userId = OneSignal.User.onesignalId

Also, do you perhaps know a good workaround to avoid the crash?

@jkasten2
Copy link
Member

jkasten2 commented Mar 1, 2024

@alenjularic @CarlBarks a fix for this is now available in OneSignal-Android-SDK 5.1.6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants