Skip to content

fix: [SDK-5698] let initialize and login reach native - #1205

Open
abdulraqeeb33 wants to merge 2 commits into
mainfrom
ar/sdk-5698-flutter
Open

abdulraqeeb33 wants to merge 2 commits into
mainfrom
ar/sdk-5698-flutter

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 in lib/onesignal_flutter.dart.

The alias, email, SMS, tag, trigger, and outcome guards stay, along with the Live Activity and removeGroupedNotifications checks.

Removing the last isMissing call in this file left the src/utils.dart import unused. flutter analyze flagged it, so it is removed.

Testing

Unit testing

test/onesignalflutter_test.dart had a test asserting an empty externalId never reached the channel. It now asserts the value is forwarded, which is the new contract.

Full suite: 272 passed. flutter analyze lib test reports no issues.

Manual testing

Not exercised on a device. It cannot be meaningfully exercised until the dependency bump: on the pinned 5.11.0, an empty app id does not fall back to the cached one.

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

@abdulraqeeb33
abdulraqeeb33 requested a review from a team November 20, 2026 16:16
Both guards returned before calling native. 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 failed.

Null is not a concern here. Dart null safety is on (sdk >=2.12.0) and both
parameters are non-nullable String, so a Dart caller cannot pass null and
isMissing could only ever catch an empty string. Native handles empty on
both platforms: Android falls back to the cached app id after the
never-crash change, and iOS initialize: rejects "" through OSInputGuard.

The alias, email, SMS, tag, trigger, and outcome guards stay.

Dropping the last isMissing call made the utils import unused; flutter
analyze flagged it and it is removed. The test that asserted an empty
externalId never reached the channel now asserts it is forwarded.

DO NOT MERGE until oneSignalVersion in android/build.gradle can be bumped
to a release containing the never-crash change. It pins 5.11.0, where an
empty app id does not yet fall back to the cached one.

Co-authored-by: Cursor <cursoragent@cursor.com>
@abdulraqeeb33
abdulraqeeb33 marked this pull request as ready for review November 20, 2026 17:20
@@ -49,7 +48,6 @@ class OneSignal {
/// The initializer accepts an [appId] which the developer can get
/// from the OneSignal consoleas well as a dictonary of [launchOptions]
static Future<void> initialize(String appId) async {

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: no test covers initialize('') now. Could you add one asserting '' is forwarded and the lifecycle methods still run? As is, restoring the old guard would still pass the suite.

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.

Agreed, and the part that matters is your point that restoring the old guard would still pass the suite as written. Not added yet.

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 added in 685a8eb. Asserts '' is forwarded and that the lifecycle methods still run. Revert-checked: restoring the guard turns it red, which was your actual point.

static Future<void> initialize(String appId) async {
if (isMissing(appId, 'initialize: appId')) return;
await _channel.invokeMethod('OneSignal#initialize', {'appId': appId});
await Future.wait([

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: initialize('') after a valid init now reruns lifecycleInit, which clears pending foreground display/preventDefault caches (OSFlutterNotifications.m:124). Same as calling initialize twice today, so fine to leave.

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.

Noted, and agreed it matches calling initialize twice today.

Comment thread test/onesignalflutter_test.dart Outdated
expect(channelController.state.externalId, isNull);
});
test(
'login forwards an empty externalId to native, which ignores it',

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: the name says native ignores it, but the test only checks forwarding. Maybe "login forwards an empty externalId to native".

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.

Agreed, the name claims more than the test checks.

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 685a8eb.

@abdulraqeeb33

Copy link
Copy Markdown
Contributor Author

Both fair. The missing initialize('') test is the one worth acting on, since you are right that restoring the old guard would still pass the suite as written.

Holding both until the blocker is resolved: this needs SDK_NEVER_CRASH_ENABLED rolled out, not just the version bump, since legacy OneSignalImp still throws on null by design. Description now leads with that.

The suite had no case for an empty appId, so restoring the old guard would
still have passed. The new test asserts '' is forwarded and that the
lifecycle methods still run; reverting the guard turns it red.

The login test name claimed native ignores the value when the test only
checks forwarding, so it now says what it checks.

Review feedback from fadi-george on #1205.

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

Copy link
Copy Markdown
Contributor Author

Follow-up: both actionable ones are fixed in 685a8eb, including the initialize('') test, which I revert-checked. The flag-rollout blocker still stands.

@fadi-george

Copy link
Copy Markdown
Collaborator

@abdulraqeeb33 title is still react-native, this is flutter

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