Skip to content

Fix crash: use postValue in resetFrontDoorBridgeUrl#2908

Merged
wmathurin merged 1 commit into
forcedotcom:devfrom
wmathurin:fix-login-crash-background-thread
May 28, 2026
Merged

Fix crash: use postValue in resetFrontDoorBridgeUrl#2908
wmathurin merged 1 commit into
forcedotcom:devfrom
wmathurin:fix-login-crash-background-thread

Conversation

@wmathurin
Copy link
Copy Markdown
Contributor

Summary

resetFrontDoorBridgeUrl() calls LiveData.setValue() but can be invoked from a background coroutine dispatcher (via onAuthFlowErrordoCodeExchange error path). This throws IllegalStateException: Cannot invoke setValue on a background thread.

Fix: use postValue(null) instead of value = null.

Context

The bug was introduced in "Modern Login Architecture (#2653)" on 2025-01-24. It only manifests when the OAuth code exchange fails (e.g., invalid consumer key, network error during exchange) — the happy path never hits this code.

Test Plan

  • Reproduced crash with invalid consumer key on React Native template app
  • Verified fix resolves crash — auth error is handled gracefully

resetFrontDoorBridgeUrl is called from onAuthFlowError which can be
invoked from a background coroutine dispatcher (via doCodeExchange).
LiveData.setValue throws IllegalStateException when called off the
main thread. Use postValue instead.
Copy link
Copy Markdown
Contributor

@JohnsonEricAtSalesforce JohnsonEricAtSalesforce left a comment

Choose a reason for hiding this comment

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

👍🏻

@codecov
Copy link
Copy Markdown

codecov Bot commented May 28, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 66.58%. Comparing base (0ec99fc) to head (7ef093b).
⚠️ Report is 3 commits behind head on dev.

Additional details and impacted files
@@             Coverage Diff              @@
##                dev    #2908      +/-   ##
============================================
+ Coverage     66.41%   66.58%   +0.17%     
- Complexity     3099     3108       +9     
============================================
  Files           226      226              
  Lines         17774    17871      +97     
  Branches       2327     2339      +12     
============================================
+ Hits          11804    11899      +95     
+ Misses         4896     4887       -9     
- Partials       1074     1085      +11     
Components Coverage Δ
Analytics 48.71% <ø> (ø)
SalesforceSDK 62.88% <89.81%> (+0.35%) ⬆️
Hybrid 59.30% <ø> (ø)
SmartStore 78.22% <ø> (ø)
MobileSync 82.12% <ø> (ø)
Files with missing lines Coverage Δ
...src/com/salesforce/androidsdk/ui/LoginViewModel.kt 89.60% <100.00%> (ø)

... and 4 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@wmathurin wmathurin merged commit 15c06fe into forcedotcom:dev May 28, 2026
18 checks passed
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