Skip to content

Conversation

@jinliu9508
Copy link
Contributor

@jinliu9508 jinliu9508 commented Dec 12, 2025

Description

One Line Summary

Fix NPE from setting timezone on app focus when onesignalId is missing from the property model.

Details

Motivation

Fix NPE from setting timezone on app focus when onesignalId is missing from the property model.

This change was added in #2378

Scope

Update the timezone in onSessionStart and onSessionActive instead of in UserManager.onFocus, since the propertiesModel may not be fully initialized at that time.

Related Issues

#2413

Testing

Unit testing

Add a test case for updating the timezone when onSessionStart() and onSessionActive is called.

Manual testing

Step to reproduce:

  1. Call initWithContext without an app ID. The app crashes on startup.
  2. Reopen the app, observe the error
image After fix this error does not show up anymore.

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

@github-actions
Copy link
Contributor

github-actions bot commented Dec 12, 2025

📊 Diff Coverage Report

Diff Coverage Report

Threshold: 80%

Changed Files Coverage

  • SessionListener.kt: 12/23 lines (52.2%)
    • ⚠️ Below threshold: 11 uncovered lines
  • UserManager.kt: 78/134 lines (58.2%)
    • ⚠️ Below threshold: 56 uncovered lines

Overall Coverage

90/157 lines covered (57.3%)

❌ Coverage Check Failed

Files below 80% threshold:

  • SessionListener.kt: 52.2% (11 uncovered lines)

  • UserManager.kt: 58.2% (56 uncovered lines)

📥 View workflow run

// Detect any user properties updates that changed
_propertiesModel.timezone = TimeUtils.getTimeZoneId()
// Skip updating timezone when onesignalId is not set in the property model
if (_propertiesModel.hasProperty(PropertiesModel::onesignalId.name)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be decent workaround to prevent the crash. And this method will be called frequently and the timezone could be updated later when the oneSignaId is actually available

Copy link
Contributor

@nan-li nan-li left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This guard works but there's a deeper issue. There's no clear signal in the code that setting timezone requires onesignal ID to exist first. This is the kind of implicit dependency that's impossible to catch without already knowing about it.

@abdulraqeeb33
Copy link
Contributor

This guard works but there's a deeper issue. There's no clear signal in the code that setting timezone requires onesignal ID to exist first. This is the kind of implicit dependency that's impossible to catch without already knowing about it.

Good catch on this @nan-li . i hope the new fix that we discussed will address this issue.

@jinliu9508
Copy link
Contributor Author

@nan-li @abdulraqeeb33 I have updated with another approach by updating the timezone onSessionStart and onSessionActive. Please take a look.

Copy link
Contributor

@abdulraqeeb33 abdulraqeeb33 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the newer approach looks fine to me, but the tests are broken @jinliu9508

@jinliu9508
Copy link
Contributor Author

@abdulraqeeb33

the newer approach looks fine to me, but the tests are broken @jinliu9508

The test is now removed because onFocus no longer updates timezone

@jinliu9508
Copy link
Contributor Author

@nan-li

This guard works but there's a deeper issue. There's no clear signal in the code that setting timezone requires onesignal ID to exist first. This is the kind of implicit dependency that's impossible to catch without already knowing about it.

I have updated the PR description to include a manual test I found that can reproduce the exact error. After the fix we can see that the error for this particular logical path is fixed.

@jinliu9508 jinliu9508 requested a review from nan-li December 18, 2025 17:03
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.

4 participants