Skip to content

Guard against nil account in createOrUpdateAccountWithAuthToken callback - #25967

Open
jkmassel wants to merge 1 commit into
trunkfrom
jkmassel/nullable-account-callback
Open

Guard against nil account in createOrUpdateAccountWithAuthToken callback#25967
jkmassel wants to merge 1 commit into
trunkfrom
jkmassel/nullable-account-callback

Conversation

@jkmassel

@jkmassel jkmassel commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Follows the same pattern as #25964.

Summary

  • AccountService.createOrUpdateAccountWithAuthToken:success:failure: declares its success block parameter WPAccount * _Nonnull, but the implementation resolves the account via existingObjectWithID:error:, which can return nil.
  • Swift imports the callback as non-optional WPAccount, so the single caller (WordPressComSyncService) cannot guard it.

Root Cause

AccountService.m passes the result of existingObjectWithID:error: straight into the _Nonnull success block. If the object can't be re-resolved on the main context (a Core Data race), account is nil. WordPressComSyncService.syncOrAssociateBlogs(account:) then reads the Swift-native isDefaultWordPressComAccount on it — risking a trap or wrong-account behavior in the login/sync path.

Fix

  • Mark the success block parameter WPAccount * _Nullable in AccountService.h/.m so the annotation is honest. The implementation body already passes nil legally.
  • Guard the account in WordPressComSyncService.syncWPCom(...); on nil, fail through the existing onFailure path.

Test plan

  • WordPress app builds (generic iOS Simulator).
  • SwiftLint clean.
  • Signing in to a WordPress.com account still syncs the account and its blogs.

Part of an audit of Objective-C non-null declarations whose implementations can return nil; see #25964 for the first fix in the series.

@jkmassel jkmassel added this to the 27.3 milestone Sep 1, 2026
@jkmassel jkmassel self-assigned this Sep 1, 2026
@wpmobilebot

Copy link
Copy Markdown
Contributor
App Icon📲 You can test the changes from this Pull Request in WordPress by scanning the QR code below to install the corresponding build.
App NameWordPress
ConfigurationRelease-Alpha
Build Number34120
VersionPR #25967
Bundle IDorg.wordpress.alpha
Commit514a904
Installation URL3iges7j0uls9g
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@wpmobilebot

Copy link
Copy Markdown
Contributor
App Icon📲 You can test the changes from this Pull Request in Jetpack by scanning the QR code below to install the corresponding build.
App NameJetpack
ConfigurationRelease-Alpha
Build Number34120
VersionPR #25967
Bundle IDcom.jetpack.alpha
Commit514a904
Installation URL515ada6pm29v0
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@jkmassel
jkmassel requested a review from crazytonyli September 1, 2026 20:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants