Skip to content

fix: [SDK-5698] let Initialize and Login reach native on Android - #918

Open
abdulraqeeb33 wants to merge 3 commits into
mainfrom
ar/sdk-5698-unity
Open

abdulraqeeb33 wants to merge 3 commits into
mainfrom
ar/sdk-5698-unity

Conversation

@abdulraqeeb33

@abdulraqeeb33 abdulraqeeb33 commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Important

Blocked on the never-crash rollout, not just an AAR/version bump. See "Why this cannot merge yet" below. Native's never-crash behavior sits behind SDK_NEVER_CRASH_ENABLED, which defaults to off, and the legacy path still throws on a null.

Description

One Line Summary

Remove input validation that was added to the wrapper by mistake, so the native SDK owns it.

Details

Motivation: this undoes a wrapper-side mistake

SDK-5327 added null and empty checks to every client SDK at once, wrappers included. For most APIs that was harmless duplication. For initialize and login it was the wrong layer, and it caused a bug.

Validation belongs in the native SDK. It is the only layer that knows what an invalid input should actually do, and duplicating it per wrapper means six implementations drifting from each other and from native. The wrapper's job is to pass the call through.

initialize shows why this matters concretely. Native falls back to the app ID cached by an earlier launch when the one it is given is unusable. The wrapper guard returned before native was ever called, so that fallback never ran, the SDK stayed unstarted, and the next login failed. The wrapper was not preventing a bug, it was creating one. That is the SDK-5366 chain, and the fix is to delete the guard rather than to catch the symptom downstream.

So this PR is a correction, not a feature: the check should have gone into native in the first place.

Why this cannot merge yet

Native Android's never-crash behavior is behind a remote feature flag, and it is off by default:

// NeverCrashKillSwitch.kt
// Absent means the legacy implementation, so the rollout stays off until Turbine sends the flag.
@Volatile
var useLegacy: Boolean = true

When the flag is off, NeverCrashKillSwitch.create() returns the legacy OneSignalImp, which still throws by design:

if (appId == null) throw nullParameter("initWithContext", "appId")
if (externalId == null) throw nullParameter("login", "externalId")

The helper is commented "The kill switch's fallback keeps the crash a Java null used to hit in the non-null facade." The nullable signatures from #2841 are real, but the log-and-ignore behavior behind them only applies on the V2 path.

So merging needs both:

  1. A released Android SDK containing the never-crash change, and the pin bumped to it.
  2. SDK_NEVER_CRASH_ENABLED actually rolled out, since the flag is evaluated per app from mirrored startup flags.

Until then, removing the guard reintroduces exactly the SDK-5304 crash for every app the flag has not reached. My original description claimed Android already logs and ignores a null; that was wrong, and it was wrong in the same way across all six wrapper PRs.

Scope

Only Initialize and Login, and only in OneSignalAndroid.cs.

The alias, email, SMS, tag, trigger, and outcome guards stay on both platforms. Those native parameters are still non-null.

Why the iOS guards stay

OneSignaliOS.cs keeps both guards, and they changed from redundant duplication to load-bearing. OneSignalUnityBridge.mm forwards straight through:

void ...(const char* externalId) {
    [OneSignal login:TO_NSSTRING(externalId)];
}

Native iOS login: passes externalId into a non-optional Swift parameter with no nil handling, so a null has to stop in the wrapper. Both sites gained a comment, since they otherwise read as leftover duplication that a future cleanup would delete.

(iOS initialize: does handle nil and falls back to the cached app id, but the guard is kept there for symmetry with Login and because the empty-string case still needs rejecting.)

Testing

Unit testing

None. The change only removes two early returns; this repo has no unit test project covering the platform bridges.

Manual testing

Not exercised on a device, and it cannot be meaningfully exercised until the dependency bump: on the pinned 5.11.0, a null still reaches non-null Kotlin parameters.

Affected code checklist

  • Notifications
  • 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
  • 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.
  • I have reviewed this PR myself, ensuring it meets each checklist item

Android native now takes a nullable appId and externalId and logs and
returns, so the wrapper guard only gets in the way. Returning early from
Initialize was the damaging one: native falls back to the cached app id,
and short-circuiting skipped that fallback, leaving the SDK unstarted so
the next Login threw IllegalStateException.

The iOS implementation keeps both guards, and they are now load-bearing
rather than redundant. OneSignalUnityBridge.mm forwards straight to
[OneSignal login:], which passes externalId into a non-optional Swift
parameter with no nil handling. Both sites gained a comment, because they
otherwise read as leftover duplication.

Scope is only these two methods. The alias, email, SMS, tag, trigger, and
outcome guards stay on both platforms: those native parameters are still
non-null.

DO NOT MERGE until OneSignalAndroidDependencies.cs can be bumped to a
release containing the never-crash change. It pins 5.11.0, where
initWithContext and login take non-null Kotlin parameters, so a null would
reach them and throw NullPointerException.

Co-authored-by: Cursor <cursoragent@cursor.com>
@abdulraqeeb33
abdulraqeeb33 requested a review from a team November 20, 2026 16:15
@abdulraqeeb33
abdulraqeeb33 marked this pull request as ready for review November 20, 2026 17:21
Comment on lines -133 to -134
if (InputGuard.IsMissing(appId, "initialize: appId"))
return;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Non-blocking: with this guard gone, _completedInit(appId) at the end of Initialize now runs when appId is null or "". It sets OneSignalPlatform.AppId to that and fires OnInitialize(null), so the attribution hook sends a null app id. Maybe skip _completedInit when appId is missing?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Real gap, not fixed. Holding with the rest of the set until the flag rollout, so it gets done once rather than patched blind.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Now fixed in 0cfd95f. _completedInit only runs when the app id is non-empty, so OnInitialize no longer gets a value the SDK is not using.

Comment on lines +146 to +147
// The iOS bridge forwards straight to [OneSignal initialize:], whose externalId
// counterpart reaches a non-optional Swift parameter. Null has to stop here.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nit: this gives the login/Swift reason, but iOS initialize: handles nil and falls back to the cached app id. The real reasons are symmetry with Login and rejecting "". Could the comment say that instead?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 0965bfc. The comment now says initialize: handles nil and it is "" that gets rejected without falling back.

Native initialize: handles nil; it is the empty string it rejects without
falling back to the cached app id. The previous comment borrowed Login's
non-optional Swift reasoning, which does not apply here.

Review feedback from fadi-george on #918.

Co-authored-by: Cursor <cursoragent@cursor.com>
@abdulraqeeb33

Copy link
Copy Markdown
Contributor Author

Comment reason fixed in 0965bfc: native initialize: does handle nil, it is "" it rejects without falling back, so that is what the comment says now.

_completedInit is a fair catch and not addressed yet. Holding it because this whole set is blocked on SDK_NEVER_CRASH_ENABLED being rolled out rather than just the version bump, which the description now leads with.

With the guard gone, _completedInit ran for a null or empty appId, setting
OneSignalPlatform.AppId to it and firing OnInitialize with a value the SDK
is not actually using. Native may have resolved a cached app id instead.

Review feedback from fadi-george on #918.

Co-authored-by: Cursor <cursoragent@cursor.com>
@abdulraqeeb33

Copy link
Copy Markdown
Contributor Author

Follow-up: the _completedInit gap is fixed in 0cfd95f, so nothing is outstanding from your review here. The flag-rollout blocker still stands.

@fadi-george

Copy link
Copy Markdown
Collaborator

@abdulraqeeb33 please fix the title

@fadi-george fadi-george reopened this Nov 23, 2026
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