Skip to content

[Due for payment 2026-07-23] [$250] [Sentry: APP-82E] HybridApp iOS NSRangeException in BaseViewController onBarButtonItemSelected #93840

Closed

Description

@mountiny

Sentry

https://expensify.sentry.io/issues/APP-82E

Impact (snapshot at filing)

  • Users (total since first seen): 666
  • Events: 849
  • Users (last 14d, 9.4.x releases): 9
  • First seen: 2026-03-20
  • Last seen: ongoing
  • Platform: iOS HybridApp (OldDot BaseViewController)
  • App version(s): 9.4.x
  • Affected route(s): navigation bar button tap
  • Mechanism: nsexception

Stack trace (top frames, first-party only)

-[BaseViewController onBarButtonItemSelected:]
-[__NSArrayM objectAtIndexedSubscript:] (index 0 beyond bounds for empty array)

Suspected cause

Navigation bar button handler accesses index 0 of an empty array — likely missing menu items when bar button is tapped.

Reproduction

Unknown — see Sentry events linked from the Sentry issue.

Related

  • Prior GH issues: Expensify/Expensify#63286 (closed, same signature)
Upwork Automation - Do Not Edit
Issue OwnerCurrent Issue Owner: @mallenexpensify

Activity

  1. self-assigned this
    on Jun 17, 2026
  2. added
    ExternalAdded to denote the issue can be worked on by a contributor
    Help WantedApply this label when an issue is open to proposals by contributors
    BugSomething is broken. Auto assigns a BugZero manager.
    on Jun 17, 2026
  3. melvin-bot commented on Jun 17, 2026

    @melvin-bot

    Triggered auto assignment to Contributor-plus team member for initial proposal review - @ChavdaSachin (External)

  4. melvin-bot commented on Jun 17, 2026

    @melvin-bot
  5. godzillaxbox19982014-lgtm commented on Jun 17, 2026

    @godzillaxbox19982014-lgtm

    Proposal

    Please re-state the problem that we are trying to solve in this issue.

    [$250] [Sentry: APP-82E] HybridApp iOS NSRangeException in BaseViewController onBarButtonItemSelected

    What is the root cause of that problem?

    I traced this to the path that handles APP, HybridApp, NSRangeException:

    • src/libs/actions/HybridApp/index.ts:112 (clearPreloadedRoutes): Navigation.clearPreloadedRoutes();
    • src/libs/Navigation/guards/OnboardingGuard.ts:172 (isFirstTimeHybridAppTransition): const isFirstTimeHybridAppTransition = (CONFIG.IS_HYBRID_APP && tryNewDot?.isHybridAppOnboardingCompleted !== true) ?? false;
    • src/libs/Navigation/guards/OnboardingGuard.ts:195 (OnboardingGuard): isFirstTimeHybridAppTransition ||
    • The local evidence matches this recurring failure shape: native callback assumes current policy/report still exists. Here, src/libs/actions/HybridApp/index.ts:112 and src/libs/Navigation/guards/OnboardingGuard.ts:172 do not agree on the same APP, HybridApp, NSRangeException value, so the user-visible path can show a missing or stale state even though nearby data already has the needed context.

    What changes do you think we should make in order to solve the problem?

    • Update src/libs/actions/HybridApp/index.ts:112 to derive APP, HybridApp, NSRangeException from the matched app state path that owns this flow before the value is consumed.
    • Carry the same normalized value through src/libs/Navigation/guards/OnboardingGuard.ts:172; that follows the safer family move to add the guard at the ownership boundary, not only at render, so the write/optimistic/read paths agree instead of only changing the visible component.
    • Keep the change inside the Sentry Crash, Null/Undefined, Native Hybrid surface and avoid changing do not hide crashes with blanket catch, native platform differences.

    What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?

    1. Add or update a regression in tests/unit/**/*.ts for the exact issue flow: [$250] [Sentry: APP-82E] HybridApp iOS NSRangeException in BaseViewController onBarButtonItemSelected.
    2. Cover the counter-case near src/libs/actions/HybridApp/index.ts:112 so valid existing APP, HybridApp, NSRangeException behavior still works.
    3. Manually repeat the issue steps after the patch and confirm the visible state/action is no longer stale.

    What alternative solutions did you explore? (Optional)

    • I would not add a broad new condition outside these referenced paths; the safer fix is to keep APP, HybridApp, NSRangeException consistent at the first read/write boundary shown above.
  6. MelvinBot commented on Jun 17, 2026

    @MelvinBot
    Contributor

    Issue Analysis

    Root Cause: This is a native iOS (Objective-C) crash in OldDot, not in the App (React Native/TypeScript) codebase. The handler -[BaseViewController onBarButtonItemSelected:] does an unguarded array access (self.titleButtonsCallback[button.tag]). When the bar button is tapped while the callbacks array is empty (or button.tag is out of range), objectAtIndexedSubscript: throws NSRangeException ("index 0 beyond bounds for empty array").

    This is a dormant native bug — onBarButtonItemSelected: assumes there is always a callback registered at button.tag, but the array can be empty when the bar button's state and the registered callbacks get out of sync (e.g. a modal/menu transition leaves the toolbar buttons present but their callbacks cleared).

    ⚠️ The fix is in Mobile-Expensify (OldDot iOS native code), not in Expensify/App. BaseViewController.m is Objective-C and lives outside this repo, so this cannot be implemented as an App PR. This needs to be escalated to an internal engineer with Mobile-Expensify write access. I was unable to confirm the current state of that file because I don't have access to the Mobile-Expensify repo.

    This is essentially a regression of Expensify/Expensify#63286 (2017), which has the identical crash signature. That issue was fixed with a bounds check — Android already has the equivalent guard. The recommended native fix is the same one that resolved #63286:

    - (void)onBarButtonItemSelected:(UIBarButtonItem *)button {
        if ([self.titleButtonsCallback count] <= button.tag) {
            LOG_ALERT(@"Unable to perform button item callback because index is out of bounds");
            return;
        }
        [YAPLJS callFunction:self.titleButtonsCallback[button.tag]];
    }

    An internal engineer should also investigate why the callbacks array is empty when the button is still tappable (the root state desync), since the bounds check above is a crash guard, not a behavioral fix.

    Investigation details & evidence
    • Stack trace is Objective-C method syntax (-[ClassName method:]), confirming native OldDot code, not JS:
      • -[BaseViewController onBarButtonItemSelected:]
      • -[__NSArrayM objectAtIndexedSubscript:] (index 0 beyond bounds for empty array)
    • Platform: iOS HybridApp, OldDot BaseViewController — the OldDot wrapper, whose native iOS source is in Mobile-Expensify.
    • Prior fix evidence: In Expensify/Expensify#63286, AndrewGable landed the exact bounds-check above in iOS/Expensify/BaseViewController.m, and noted Android has a parallel null check. A repro from that issue: opening the create-expense menu, cancelling out of nested modals, then tapping Close left the toolbar in a state where the callback array no longer matched the buttons.
    • Since this issue's signature matches [Due for payment 2025-06-12] [Due for payment 2025-06-11] Reports - "Approve" is not shown in LHN when user is second approver of a policy #63286 exactly and the crash is recurring (first seen 2026-03-20, 666 users), the historical guard appears to be missing or no longer covering this path in the current Mobile-Expensify BaseViewController.m — needs confirmation by someone with repo access.

    Note on the existing proposal: the proposal above referencing src/libs/actions/HybridApp/index.ts and src/libs/Navigation/guards/OnboardingGuard.ts does not match this crash — those are TypeScript files unrelated to a native Objective-C NSRangeException in BaseViewController. The crash is entirely in native iOS code.


    Next Steps: This requires a Mobile-Expensify change and should be handed to an internal engineer with access to that repo. Reply with @MelvinBot <your feedback> to refine this analysis.

  7. yusufdeveloper2903 commented on Jun 17, 2026

    @yusufdeveloper2903
    Contributor

    Proposal

    What is the root cause of that problem?

    This is a native Objective-C crash in OldDot, not in NewDot/App TypeScript. The stack frames use ObjC method syntax (-[BaseViewController onBarButtonItemSelected:], -[__NSArrayM objectAtIndexedSubscript:]), and BaseViewController lives in the OldDot iOS source under Mobile-Expensify/iOS, per the HybridApp layout doc:

    - 📂 [**iOS**](https://github.com/Expensify/Mobile-Expensify/tree/main/iOS): Expensify Classic iOS specific code
    - 📂 [**app**](https://github.com/Expensify/Mobile-Expensify/tree/main/app): Expensify Classic JavaScript logic (aka YAPL)

    Causal chain:

    1. OldDot builds the navigation-bar buttons from a JS-supplied config. Each UIBarButtonItem is installed on the navigationItem with target/action = onBarButtonItemSelected: and its tag set to the button's index, while the matching JS callbacks are stored in a parallel backing array (the titleButtonsCallback-style array indexed by button.tag).
    2. On tap, onBarButtonItemSelected: reads callbacks[button.tag] (the objectAtIndexedSubscript: frame) and hands it to +[YAPLJS callFunction:args:].
    3. The crash is index 0 beyond bounds for empty array — i.e. button.tag == 0 but the backing callbacks array is empty (count == 0) at tap time. The UIBarButtonItem is still installed on the nav bar and still tappable, but its backing callback has been cleared/not-yet-populated. The buttons and their callbacks have desynced: the visible button outlives (or precedes) its callback entry.
    4. This desync window opens on OldDot screen/toolbar reconstruction and on HybridApp OldDot⇄NewDot handoffs, where the toolbar is rebuilt but the callbacks array is momentarily empty. A tap landing in that window (or a queued/replayed tap, double-tap during dismissal, or VoiceOver activation) indexes [0] on the empty array and throws NSRangeException.

    So: stale/early bar-button tap → onBarButtonItemSelected: indexes callbacks[button.tag] → backing array is empty → objectAtIndexedSubscript: NSRangeException.

    This is NOT the same bug as APP-7CX / #91229. That issue groups APP-82E with APP-7CX/APP-84S and asserts "a fix here should resolve all three." It will not. APP-7CX/APP-84S are AppHang watchdog terminations caused by re-entrant JSC lock contention inside LogSyncerManager.sendLogPacket (the main thread blocking on JSC::JSLock while already inside a YAPLJS callFunction frame). APP-82E (this issue) is a synchronous NSRangeException thrown before any JS runs — the array is empty, so the subscript fails. A LogSyncerManager re-entrancy/serial-queue fix leaves the callbacks array just as empty and does not touch this crash. Different fault, different fix; tracking it under the deadlock family will close this with a fix that never executed on this path.

    This crash signature is also a regression of the long-standing OldDot BaseViewController guard: Android already carries the parallel range/null check on this exact path, and the historical iOS fix added the same bounds check on BaseViewController.m. The guard is missing or no longer covers this reconstruction/handoff path.

    What changes do you think we should make in order to solve the problem?

    Two layers, reuse-first:

    1. Restore the bounds/tag guard in onBarButtonItemSelected: — the same defensive check Android already has and that historically existed on iOS. Before indexing, bail when the tag is out of range:

      if (button.tag < 0 || (NSUInteger)button.tag >= self.titleButtonsCallback.count) {
          LOG_ALERT(@"onBarButtonItemSelected: tag out of bounds, skipping callback");
          return;
      }

      This is the minimal crash guard and converts the fatal NSRangeException into a logged no-op, matching the existing Android behavior on the same handler.

    2. Fix the desync at the source so the guard is rarely hit: install the UIBarButtonItems and populate the backing callbacks array atomically when the toolbar is (re)built — set the callbacks before (or in the same step as) assigning navigationItem's bar button items, and when clearing callbacks also clear/disable the installed buttons. That closes the window where a button is tappable with no matching callback (the actual user-visible "tap does nothing" case behind the crash).

    The exact symbol names (titleButtonsCallback, LOG_ALERT) should be confirmed against the current Mobile-Expensify/iOS/.../BaseViewController.m; minor changes/improvements can be discussed in the PR phase. This requires Mobile-Expensify write access.

    What alternative solutions did you explore? (Optional)

    Guard only inside +[YAPLJS callFunction:args:] (null/range check before invoking). This catches the crash globally but hides the desync everywhere and changes shared bridge semantics for every call site; fixing at onBarButtonItemSelected: plus the atomic button/callback build is more targeted, preserves the Android parity, and addresses the underlying state mismatch rather than only the symptom.

  8. KJ21-ENG commented on Jun 17, 2026

    @KJ21-ENG
    Contributor

    Proposal

    What is the root cause of that problem?

    The crash is at the native OldDot navigation-bar tap boundary, not in NewDot JS. The Sentry stack in the issue says -[BaseViewController onBarButtonItemSelected:] calls -[__NSArrayM objectAtIndexedSubscript:] with index 0 beyond bounds for empty array, so the handler has an empty mutable array and still reads item 0 after a bar-button tap.

    The public App checkout exposes HybridApp native code through the private Mobile-Expensify submodule: the HybridApp guide says iOS HybridApp native code lives under Mobile-Expensify/iOS, and changing the root ios/ folder does not affect HybridApp builds.

    If you have access to the closed-source `Mobile-Expensify` repository, you are eligible to build HybridApp. The main difference between NewDot and HybridApp is that the native code is located in a different place. The native code is located under `./Mobile-Expensify/Android` and `./Mobile-Expensify/iOS`.
    It is vital to understand, that modifying any code in `./android` and `./ios` folders in the root of the project **will not affect the HybridApp build at all.** In this case, if you'd like to change native code, you have to go to `./Mobile-Expensify/Android` and `./Mobile-Expensify/iOS` first. This is **especially important** when you want to remove native cache or `Pods` manually.

    The App-side ReactNativeHybridApp iOS module is only the standalone NewDot stub; its methods just log/reject calls that should never run in standalone NewDot, so it is not the crashing BaseViewController handler.

    - (void)getHybridAppSettings:(RCTPromiseResolveBlock)resolve
    reject:(RCTPromiseRejectBlock)reject {
    NSLog(@"[ReactNativeHybridApp] `getHybridAppSettings` should never be called in standalone `New Expensify` app");
    reject(@"NOT_IMPLEMENTED", @"This method is not available in standalone New Expensify app", nil);
    }
    - (void)getInitialURL:(RCTPromiseResolveBlock)resolve
    reject:(RCTPromiseRejectBlock)reject {
    NSLog(@"[ReactNativeHybridApp] `getInitialURL` should never be called in standalone `New Expensify` app");
    reject(@"NOT_IMPLEMENTED", @"This method is not available in standalone New Expensify app", nil);
    }
    - (void)onURLListenerAdded {
    NSLog(@"[ReactNativeHybridApp] `onURLListenerAdded` should never be called in standalone `New Expensify` app");
    }
    - (void)signInToOldDot:(NSString *)autoGeneratedLogin autoGeneratedPassword:(NSString *)autoGeneratedPassword authToken:(NSString *)authToken email:(NSString *)email policyID:(NSString *)policyID signingInWithSAML:(NSNumber *)signingInWithSAML {
    NSLog(@"[ReactNativeHybridApp] `signInToOldDot` should never be called in standalone `New Expensify` app");
    }

    Root cause: BaseViewController.onBarButtonItemSelected: assumes the tapped navigation-bar button always resolves to at least one native menu/action item. In the failing state that item array is empty, so the unchecked first-item read raises NSRangeException instead of treating the tap as a no-op.

    What changes do you think we should make in order to solve the problem?

    Fix the BaseViewController implementation in Mobile-Expensify/iOS at the onBarButtonItemSelected: boundary:

    • Resolve the menu/action items for the tapped UIBarButtonItem exactly as the handler does today.
    • Before reading item 0, treat nil or count == 0 as an invalid/stale button state: dismiss any pending menu/popover state if needed, log the tapped button identity for diagnostics, and return without dispatching a selected-item action.
    • Keep the current one-item and multi-item paths unchanged once count > 0.
    • At the navigation-bar button configuration site, avoid leaving a button enabled when it is backed by an empty dynamic item list. If an icon-only button is valid, represent it as an explicit single action item so the tap handler never receives an ambiguous empty list.

    Scope boundaries: files touched are the BaseViewController implementation/configuration path in Mobile-Expensify/iOS only. Platforms affected: iOS HybridApp/OldDot navigation-bar taps. Code paths not touched: standalone NewDot, root App ios/, Android HybridApp, modules/hybrid-app/ios/ReactNativeHybridApp.mm, NewDot JS navigation, and backend/API contracts.

    What alternative solutions did you explore? (Optional)

    Changing the public App root ios/ project or modules/hybrid-app/ios/ReactNativeHybridApp.mm would not fix this crash: the HybridApp guide says root ios/ changes do not affect HybridApp, and the App-side module is only the standalone stub linked above.

    Fixing only the upstream JS/menu provider so it never sends an empty list would be useful cleanup, but it is not sufficient for this Sentry signature. The native bar-button tap handler is still the crash boundary and can race against async OldDot state changes, so it must guard the empty-array contract itself.

  9. github-actions commented on Jun 17, 2026

    @github-actions
    Contributor

    ⚠️ @KJ21-ENG Your proposal is a duplicate of an already existing proposal and has been automatically withdrawn to prevent spam. Please review the existing proposals before submitting a new one.

  10. 48 remaining items

  11. ChavdaSachin commented on Jul 22, 2026

    @ChavdaSachin
    Contributor

    The fix was deployed on prod v-9.4.28-2.
    There have been no instances of the crash for version 9.4.28-2 or later ✅.

    @mountiny, could you add the awaiting payment label?
    Thanks.

  12. added
    Awaiting PaymentAuto-added when associated PR is deployed to production
    and removed
    Help WantedApply this label when an issue is open to proposals by contributors
    on Jul 23, 2026
  13. melvin-bot commented on Jul 23, 2026

    @melvin-bot

    Triggered auto assignment to @mallenexpensify (Awaiting Payment)

  14. changed the title [-][$250] [Sentry: APP-82E] HybridApp iOS NSRangeException in BaseViewController onBarButtonItemSelected[/-] [+][Due for payment 2026-07-23] [$250] [Sentry: APP-82E] HybridApp iOS NSRangeException in BaseViewController onBarButtonItemSelected[/+] on Jul 23, 2026
  15. melvin-bot commented on Jul 23, 2026

    @melvin-bot

    Payment Summary

    Upwork Job

    BugZero Checklist (@mallenexpensify)

    • I have verified the correct assignees and roles are listed above and updated the necessary manual offers
    • I have verified that there are no duplicate or incorrect contracts on Upwork for this job (https://www.upwork.com/ab/applicants/2067266175046968936/hired)
    • I have verified the PR was not reverted
    • I have applied any discounts due to bugs/regressions introduced by this PR
    • I have paid out the Upwork contracts or cancelled the ones that are incorrect
    • I have verified the payment summary above is correct
  16. ChavdaSachin commented on Jul 25, 2026

    @ChavdaSachin
    Contributor

    No BZ checklist needed

  17. mallenexpensify commented on Jul 27, 2026

    @mallenexpensify
    Contributor

    Payment Summary

    Contributor+: @ChavdaSachin due $250 via NewDot

  18. quinthar commented on Aug 19, 2026

    @quinthar
    Contributor

    Approved $250 to @ChavdaSachin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Awaiting PaymentAuto-added when associated PR is deployed to productionBugSomething is broken. Auto assigns a BugZero manager.ExternalAdded to denote the issue can be worked on by a contributorWeeklyKSv2

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions