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

Migration: Missing onesignalId during initWithContext #2009

Merged
merged 1 commit into from
Mar 1, 2024

Conversation

jinliu9508
Copy link
Contributor

@jinliu9508 jinliu9508 commented Feb 26, 2024

Description

One Line Summary

Add default subscription status if legacy user info was previously saved on the device.

Details

Motivation

We've received crash reports from this thread #1995, indicating a crash caused by a null pointer exception when calling onesignal_id during the initWithText process. After some research, I discovered that this only occurs when the push subscription status is missing during a migration from v4 to v5. The getter of the subscription status will attempt to make a change to the model, which will then be queued in the model update operation. This operation requires onesignal_id to be completed, but the id is null at the early stage. To prevent the access of onesignal_id when it is null in the early init process, this fix will add a default subscription status in case of its absence under the NO_PROPOGATE tag.

Testing

Manual testing

Step to reproduce:

  1. Perform a fresh install of v4 on an Android device. (I am using Pixel 3a API 34)
  2. Make sure the player is created and shown on the OneSignal dashboard.
  3. Check out main and comment out the code that adds push subscription status when notification_types is null.
  4. Build and run the app on the same device. Notice that a null pointer exception is reported due to onesignal Id being null.

After the fix, the crash no longer exists. Some normal OneSignal operations such as logging in, logging out, sending and receiving push notifications are all working properly.

Affected code checklist

  • Notifications
    • Display
    • Open
    • Push Processing
    • Confirm Deliveries
  • Outcomes
  • Sessions
  • In-App Messaging
  • REST API requests
  • Public API changes

Checklist

Overview

  • I have filled out all REQUIRED sections above
  • PR does one thing
    • If it is hard to explain how any codes changes are related to each other then it most likely needs to be more than one PR
  • Any Public API changes are explained in the PR details and conform to existing APIs

Testing

  • I have included test coverage for these changes, or explained why they are not needed
  • All automated tests pass, or I explained why that is not possible
  • I have personally tested this on my device, or explained why that is not possible

Final pass

  • Code is as readable as possible.
    • Simplify with less code, followed by splitting up code into well named functions and variables, followed by adding comments to the code.
  • I have reviewed this PR myself, ensuring it meets each checklist item
    • WIP (Work In Progress) is ok, but explain what is still in progress and what you would like feedback on. Start the PR title with "WIP" to indicate this.

This change is Reviewable

@jinliu9508 jinliu9508 force-pushed the v5-migration-onesignal-id-missing branch from 6d13196 to d47afde Compare February 27, 2024 19:27
@jinliu9508 jinliu9508 changed the title WIP - Null pointer exception during initWithContext Null pointer exception during initWithContext Feb 27, 2024
@jinliu9508 jinliu9508 self-assigned this Feb 27, 2024
@jinliu9508 jinliu9508 changed the title Null pointer exception during initWithContext Migration: Missing onesignalId during initWithContext Feb 27, 2024
@nan-li
Copy link
Contributor

nan-li commented Feb 28, 2024

Can you add more context / background in the PR, what the stacktrace is, linking to the GH issue related to this fix.

  • What was the root cause of this crash and how did this PR fix it?
  • How does making sure there is a default subscription status prevent the onesignal ID from being null?
  • Is the onesignal_id now no longer null at the place where it used to crash, or is it still null but no longer accessed?
  • etc.

@nan-li nan-li self-assigned this Feb 28, 2024
@jinliu9508
Copy link
Contributor Author

Can you add more context / background in the PR, what the stacktrace is, linking to the GH issue related to this fix.

  • What was the root cause of this crash and how did this PR fix it?
  • How does making sure there is a default subscription status prevent the onesignal ID from being null?
  • Is the onesignal_id now no longer null at the place where it used to crash, or is it still null but no longer accessed?
  • etc.

Good questions! I have updated the description with better explanations for why the error occurs and how the fix helps to avoid it. I hope this provides a better understanding of the PR.

@jinliu9508 jinliu9508 merged commit b296111 into main Mar 1, 2024
2 checks passed
@jinliu9508 jinliu9508 deleted the v5-migration-onesignal-id-missing branch March 1, 2024 20:57
@jkasten2 jkasten2 mentioned this pull request Mar 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants