Skip to content

[Due for payment 2026-06-22] [$250] [Sentry: APP-8BM] HybridApp iOS NSInvalidArgumentException nil object in RCTNetworking prioritizedHandlers #92413

Closed

Description

@mountiny

Sentry

https://expensify.sentry.io/issues/APP-8BM

Impact (snapshot at filing)

  • Users (total since first seen): 619
  • Events: 624
  • Users (last 14d, releases 9.3.89–9.3.91): 5
  • First seen: 2026-03-23
  • Last seen: now (ongoing)
  • Platform: iOS, hybrid_app
  • App version(s): seen on 9.3.89 through 9.3.91
  • Mechanism: nsexception, fatal

Stack trace (top frames, first-party only)

-[RCTNetworking prioritizedHandlers]
  -> -[RCTNetworking handlerForRequest:]
  -> -[RCTNetworking sendRequest:responseType:...]
  -> __RCTAppSetupDefaultModuleFromClass_block_invoke_2
  -> +[NSArray arrayWithObjects:count:]  (nil object at index 3)

Suspected cause

RCTNetworking builds the prioritized handlers array with a nil entry — likely a race or a handler that failed to register on HybridApp startup or during an in-flight network request.

Reproduction

Unknown deterministically — crashes during RCTNetworking request dispatch on HybridApp iOS. See linked Sentry events.

Related

  • Sibling Sentry IDs (if any): none identified
  • Prior GH issues: none
  • Production scan: releases 9.3.89, 9.3.90, 9.3.91 (2026-06-02)
Upwork Automation - Do Not Edit
Issue OwnerCurrent Issue Owner: @mallenexpensify

Activity

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

    @melvin-bot

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

  5. changed the title [-][Sentry: APP-8BM] HybridApp iOS NSInvalidArgumentException nil object in RCTNetworking prioritizedHandlers[/-] [+][$250] [Sentry: APP-8BM] HybridApp iOS NSInvalidArgumentException nil object in RCTNetworking prioritizedHandlers[/+] on Jun 2, 2026
  6. melvin-bot commented on Jun 2, 2026

    @melvin-bot
  7. trasnake87 commented on Jun 2, 2026

    @trasnake87
    Contributor

    Proposal

    On HybridApp iOS, the first network request dispatched after certain bridge/module-registry states fatally crashes with NSInvalidArgumentException ("nil object at index 3") instead of completing the request.

    Root cause

    The crash is not in RCTNetworking itself — that frame is just where the lazy handler list is first materialized. -[RCTNetworking handlerForRequest:] (node_modules/react-native/Libraries/Network/RCTNetworking.mm:223-267) calls -[RCTNetworking prioritizedHandlers] (RCTNetworking.mm:269-296), which on first use invokes the _handlersProvider block to build and cache the handler array:

    // node_modules/react-native/Libraries/Network/RCTNetworking.mm:276-294
    NSArray<id<RCTURLRequestHandler>> *newHandlers = _handlersProvider
        ? _handlersProvider(self.moduleRegistry)
        : [self.bridge modulesConformingToProtocol:@protocol(RCTURLRequestHandler)];
    // ...sortedArrayUsingComparator:... then  _handlers = newHandlers;

    That _handlersProvider is the block installed in RCTAppSetupDefaultModuleFromClass — reached because -[RCTReactNativeFactory getModuleInstanceFromClass:] (RCTReactNativeFactory.mm:193) falls through to it for RCTNetworking. The block is __RCTAppSetupDefaultModuleFromClass_block_invoke_2 in the stack trace, and it builds the default handler list like this:

    // node_modules/react-native/Libraries/AppDelegate/RCTAppSetupUtils.mm:101-112
    } else if (moduleClass == RCTNetworking.class) {
        return [[moduleClass alloc]
            initWithHandlersProvider:^NSArray<id<RCTURLRequestHandler>> *(RCTModuleRegistry *moduleRegistry) {
              NSArray *URLRequestHandlerModules =
                  extractModuleConformingToProtocol(moduleRegistry, @protocol(RCTURLRequestHandler));
              return [@[
                [RCTHTTPRequestHandler new],                    // index 0
                [RCTDataRequestHandler new],                    // index 1
                [RCTFileRequestHandler new],                    // index 2
                [moduleRegistry moduleForName:"BlobModule"],    // index 3  <-- nil
              ] arrayByAddingObjectsFromArray:URLRequestHandlerModules];
            }];
    }

    There are two contributing factors:

    1 - Index 3 (BlobModule) can resolve to nil. The first three entries are created with +new and are never nil. The fourth, [moduleRegistry moduleForName:"BlobModule"], is a registry lookup — it resolves RCTBlobManager, which registers as RCT_EXPORT_MODULE(BlobModule) (node_modules/react-native/Libraries/Blob/RCTBlobManager.mm:45). -[RCTModuleRegistry moduleForName:] returns nil whenever that module is not (yet) instantiable: during HybridApp's OldDot↔NewDot bridge handoff the module registry is torn down/rebuilt, so there is a window where the network stack is alive and accepting requests but BlobModule resolves to nil. This matches the report exactly: iOS-only, hybrid_app, non-deterministic, "nil object at index 3".

    2 - The list is built with an Objective-C array literal, which is fatal on nil. @[ … ] compiles to +[NSArray arrayWithObjects:count:] (the bottom frame in the trace), which raises NSInvalidArgumentException the instant any element is nil. So a transiently-missing BlobModule turns a recoverable "one fewer handler" situation into a hard crash. Note the sibling image-loader block directly above (RCTAppSetupUtils.mm:92-99) is nil-safe by construction — it only ever puts +new instances (RCTBundleAssetImageLoader, RCTGIFImageDecoder) into its literal. The networking block is the only one that mixes a fallible registry lookup into a literal.

    Proposed fix

    Guard the BlobModule lookup at its source via a patch-package patch, matching the existing convention in patches/react-native/. Build the defaults in a nil-tolerant NSMutableArray and append BlobModule only when present:

    // node_modules/react-native/Libraries/AppDelegate/RCTAppSetupUtils.mm:101-112 (after)
    } else if (moduleClass == RCTNetworking.class) {
        return [[moduleClass alloc]
            initWithHandlersProvider:^NSArray<id<RCTURLRequestHandler>> *(RCTModuleRegistry *moduleRegistry) {
              NSArray *URLRequestHandlerModules =
                  extractModuleConformingToProtocol(moduleRegistry, @protocol(RCTURLRequestHandler));
              // moduleForName:"BlobModule" can be nil during HybridApp bridge transitions.
              // Build with a mutable array and skip a nil BlobModule instead of crashing the
              // @[...] literal with a nil object at index 3 (Sentry APP-8BM).
              NSMutableArray<id<RCTURLRequestHandler>> *defaultHandlers = [NSMutableArray arrayWithObjects:
                  [RCTHTTPRequestHandler new], [RCTDataRequestHandler new], [RCTFileRequestHandler new], nil];
              id<RCTURLRequestHandler> blobModule = (id<RCTURLRequestHandler>)[moduleRegistry moduleForName:"BlobModule"];
              if (blobModule) {
                [defaultHandlers addObject:blobModule];
              }
              return [defaultHandlers arrayByAddingObjectsFromArray:URLRequestHandlerModules];
            }];
    }

    [NSMutableArray arrayWithObjects: a, b, c, nil] is safe because the three +new entries are guaranteed non-nil and the trailing nil is just the varargs terminator. Ship it as patches/react-native/react-native+0.83.1+038+fix-networking-nil-blob-handler-APP-8BM.patch, e.g.:

    --- a/node_modules/react-native/Libraries/AppDelegate/RCTAppSetupUtils.mm
    +++ b/node_modules/react-native/Libraries/AppDelegate/RCTAppSetupUtils.mm
    @@ -103,12 +103,15 @@ id<RCTTurboModule> RCTAppSetupDefaultModuleFromClass(Class moduleClass, id<RCTDe
             initWithHandlersProvider:^NSArray<id<RCTURLRequestHandler>> *(RCTModuleRegistry *moduleRegistry) {
               NSArray *URLRequestHandlerModules =
                   extractModuleConformingToProtocol(moduleRegistry, @protocol(RCTURLRequestHandler));
    -          return [@[
    -            [RCTHTTPRequestHandler new],
    -            [RCTDataRequestHandler new],
    -            [RCTFileRequestHandler new],
    -            [moduleRegistry moduleForName:"BlobModule"],
    -          ] arrayByAddingObjectsFromArray:URLRequestHandlerModules];
    +          NSMutableArray<id<RCTURLRequestHandler>> *defaultHandlers = [NSMutableArray arrayWithObjects:
    +              [RCTHTTPRequestHandler new], [RCTDataRequestHandler new], [RCTFileRequestHandler new], nil];
    +          id<RCTURLRequestHandler> blobModule = (id<RCTURLRequestHandler>)[moduleRegistry moduleForName:"BlobModule"];
    +          if (blobModule) {
    +            [defaultHandlers addObject:blobModule];
    +          }
    +          return [defaultHandlers arrayByAddingObjectsFromArray:URLRequestHandlerModules];
             }];
       }

    Add the matching entry to patches/react-native/details.md (Reason: prevents NSInvalidArgumentException when BlobModule is transiently nil during HybridApp bridge transitions; E/App issue: #92413; Sentry: APP-8BM).

    Why this approach

    Fixing it at the source — the provider block where the nil is introduced — is strictly better than filtering nils downstream in RCTNetworking.prioritizedHandlers, because the literal crashes before RCTNetworking ever sees the array, so a downstream guard would never run. The change is also behavior-preserving: when BlobModule is present the handler set is byte-for-byte identical (same order, same priorities), and when it is transiently absent the app simply lacks a blob handler for that brief window instead of crashing — RCTNetworking.handlerForRequest: already tolerates a shorter list and the cache is rebuilt on the next bridge. This is the same patch-package mechanism Expensify already uses for native RN crash fixes such as react-native+0.83.1+037+fix-deadlock-APP-7B2.patch and …+019+fix-crash-when-deleting-expense.patch, and it mirrors the nil-safe construction already used by the adjacent image-loader provider block. The App's own custom handler (ios/NewExpensify/OriginImageRequestHandler.mm, handlerPriority 4) is appended through URLRequestHandlerModules and is unaffected.

  8. KJ21-ENG commented on Jun 2, 2026

    @KJ21-ENG
    Contributor

    Proposal

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

    HybridApp iOS can crash while React Native is dispatching a network request. The fatal exception is NSInvalidArgumentException from +[NSArray arrayWithObjects:count:] because RCTNetworking builds its prioritized URL request handler list with a nil object.

    What is the root cause of that problem?

    Expensify is on React Native 0.83.1:

    "react-native": "0.83.1",

    In RN 0.83.1, RCTAppSetupDefaultModuleFromClass() creates the default iOS RCTNetworking handler provider with an Objective-C array literal. The fourth entry is a nullable module-registry lookup:

    https://github.com/facebook/react-native/blob/v0.83.1/packages/react-native/Libraries/AppDelegate/RCTAppSetupUtils.mm#L101-L111

    That lookup asks for BlobModule, and RCTModuleRegistry can return nil when neither the bridge nor TurboModule registry can provide the module at that moment:

    https://github.com/facebook/react-native/blob/v0.83.1/packages/react-native/React/Base/RCTModuleRegistry.m#L32-L54

    So the trigger is a network request reaching RCTNetworking.handlerForRequest(), the mechanism is prioritizedHandlers invoking the provider before it can sort or filter handlers, and the impact is that the Objective-C array literal crashes as soon as the BlobModule slot is nil:

    https://github.com/facebook/react-native/blob/v0.83.1/packages/react-native/Libraries/Network/RCTNetworking.mm#L223-L229

    https://github.com/facebook/react-native/blob/v0.83.1/packages/react-native/Libraries/Network/RCTNetworking.mm#L269-L278

    This matches Sentry's nil object at index 3: the first three entries are freshly allocated HTTP/data/file handlers, while index 3 is the nullable BlobModule lookup. App's custom dependency-provider handlers are appended after this default array, so they cannot be the nil object that crashes this stack.

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

    Add a React Native patch for RCTAppSetupUtils.mm so the iOS networking handler list is built without placing the nullable BlobModule lookup inside an array literal.

    The patch should:

    • Create the default handler list from the non-null RCTHTTPRequestHandler, RCTDataRequestHandler, and RCTFileRequestHandler instances.
    • Read id blobModule = [moduleRegistry moduleForName:"BlobModule"].
    • Append blobModule only when it conforms to RCTURLRequestHandler.
    • Append URLRequestHandlerModules from extractModuleConformingToProtocol(...) after that, preserving the existing dependency-provider extension point.

    This preserves normal HTTP/data/file requests, keeps blob URL handling when BlobModule is registered, and turns the missing/transient blob module case into "no blob handler available" instead of crashing unrelated requests. App already ships RN fixes through patch-package, including HybridApp crash fixes, and the patch runner applies App patches in HybridApp installs:

    find ./patches -type f -name '*.patch' -exec cp {} "$TEMP_PATCH_DIR" \;
    if [[ "$IS_HYBRID_APP_REPO" == "true" && "$NEW_DOT_FLAG" == "false" ]]; then
    find ./Mobile-Expensify/patches -type f -name '*.patch' -exec cp {} "$TEMP_PATCH_DIR" \;
    fi
    if ! npx patch-package --patch-dir "$TEMP_PATCH_DIR" --error-on-fail --color=always; then

    Use the next available RN patch filename, for example patches/react-native/react-native+0.83.1+038+fix-ios-networking-nil-blob-handler.patch, and document it in patches/react-native/details.md.

    Scope boundaries: files touched are patches/react-native/react-native+0.83.1+038+fix-ios-networking-nil-blob-handler.patch for node_modules/react-native/Libraries/AppDelegate/RCTAppSetupUtils.mm inside the RCTNetworking default-module provider, plus patches/react-native/details.md for patch documentation. Platforms affected are iOS native and HybridApp iOS through RN networking initialization. Do not change JS request code, backend/API behavior, Android networking, RCTBlobManager behavior when the module exists, or App's custom OriginImageRequestHandler.

    What alternative solutions did you explore? (Optional)

    Filtering nil handlers inside RCTNetworking.prioritizedHandlers is too late because the crash happens while the provider constructs the array it returns.

    Creating a new fallback RCTBlobManager instance would avoid the nil array entry, but it risks splitting blob storage from the registered JS BlobModule. Skipping only the missing blob handler is narrower and keeps blob support unchanged whenever the real module exists.

    Treating this as a private Mobile-Expensify-only HybridApp issue is also weaker here. The crash line is in public React Native 0.83.1 source, and the public App repo already has the patch-package path that HybridApp builds use for RN patches.

  9. MelvinBot commented on Jun 2, 2026

    @MelvinBot
    Contributor

    Proposal

    Confidence: High — the Sentry stack trace matches the React Native source frame-for-frame.

    What is the root cause of that problem?

    The crash happens inside React Native core, in the RCTNetworking URL-request-handlers provider that ships with RN 0.83.1.

    When RCTNetworking dispatches its first network request, it lazily builds and caches its list of request handlers in -[RCTNetworking prioritizedHandlers], which invokes the handlersProvider block defined in RCTAppSetupUtils.mm. That block returns an Objective-C array literal of four handlers:

    index 0: [RCTHTTPRequestHandler new]
    index 1: [RCTDataRequestHandler new]
    index 2: [RCTFileRequestHandler new]
    index 3: [moduleRegistry moduleForName:"BlobModule"]   <-- can be nil
    

    An array literal @[...] compiles to +[NSArray arrayWithObjects:count:]. On HybridApp iOS, [moduleRegistry moduleForName:"BlobModule"] sometimes returns nil (the BlobModule / RCTBlobManager is not present in the module registry at the moment the first request triggers handler construction). Inserting nil into the literal throws NSInvalidArgumentException — "attempt to insert nil object at index 3" — which is fatal.

    This explains every reported symptom: the exact exception, "nil object at index 3", the __RCTAppSetupDefaultModuleFromClass_block_invoke_2 frame (the 2nd handler-provider block), the prioritizedHandlers → handlerForRequest: → sendRequest: chain, and why it's non-deterministic (it only fires on the first in-flight request when BlobModule happens to be unregistered/not-yet-ready).

    Code evidence

    The handler array is built here (local: App/node_modules/react-native/Libraries/AppDelegate/RCTAppSetupUtils.mm lines 103–112, unpatched RN 0.83.1):

    RCTAppSetupUtils.mm (RN v0.83.1)

    } else if (moduleClass == RCTNetworking.class) {
      return [[moduleClass alloc]
          initWithHandlersProvider:^NSArray<id<RCTURLRequestHandler>> *(RCTModuleRegistry *moduleRegistry) {
            NSArray *URLRequestHandlerModules =
                extractModuleConformingToProtocol(moduleRegistry, @protocol(RCTURLRequestHandler));
            return [@[
              [RCTHTTPRequestHandler new],
              [RCTDataRequestHandler new],
              [RCTFileRequestHandler new],
              [moduleRegistry moduleForName:"BlobModule"],   // index 3 — nil here ⇒ crash
            ] arrayByAddingObjectsFromArray:URLRequestHandlerModules];
          }];
    }

    It is invoked lazily, on a request, in -[RCTNetworking prioritizedHandlers] (local: App/node_modules/react-native/Libraries/Network/RCTNetworking.mm):

    RCTNetworking.mm (RN v0.83.1)

    - (id<RCTURLRequestHandler>)handlerForRequest:(NSURLRequest *)request {
      ...
      NSArray<id<RCTURLRequestHandler>> *handlers = [self prioritizedHandlers];   // builds via _handlersProvider
    }
    - (NSArray<id<RCTURLRequestHandler>> *)prioritizedHandlers {
      ...
      NSArray *newHandlers = _handlersProvider ? _handlersProvider(self.moduleRegistry) : ...;   // runs the block above
    }

    This is core RN — none of App's 37 existing react-native+0.83.1+* patches touch this file, so the local copy matches upstream.

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

    Make the handler array construction nil-safe via a new patch-package patch on react-native (e.g. patches/react-native/react-native+0.83.1+038+fix-crash-APP-8BM.patch).

    Instead of placing [moduleRegistry moduleForName:"BlobModule"] directly inside the array literal, fetch it into a local variable first and only append it when it is non-nil (build a NSMutableArray with the three always-available handlers, conditionally add the BlobModule, then arrayByAddingObjectsFromArray: the rest). This eliminates the fatal exception regardless of why BlobModule is momentarily missing, and matches the precedent of App's other Sentry-driven RN native patches (e.g. react-native+0.83.1+037+fix-deadlock-APP-7B2.patch).

    Because HybridApp iOS builds consume the App submodule's patched react-native pod, this App-repo patch fixes the HybridApp crash without any change required elsewhere.

    What alternative solutions did you explore? (Optional)

    • Find why BlobModule is unregistered on HybridApp (a Mobile-Expensify native host / startup-race investigation). Worth doing as a follow-up to address the underlying cause, but the defensive patch above stops the fatal crash immediately and is the lower-risk, App-only fix. The nil-guard is correct to keep even if the registration issue is later resolved, since RN treats a missing BlobModule as non-fatal everywhere else.

    Next Steps for Contributor+ team:
    To accept: @MelvinBot implement this to create a draft PR.
    To refine: @MelvinBot <your feedback>
    To reject: Explain why you are rejecting Melvin's proposal.

  10. 46 remaining items

  11. melvin-bot commented on Jun 25, 2026

    @melvin-bot

    @mallenexpensify Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!

  12. mallenexpensify commented on Jun 25, 2026

    @mallenexpensify
    Contributor

    Payment Summary

    Contributor+: @DylanDylann due $250 via NewDot

    no tests were needed on PR

  13. DylanDylann commented on Jun 26, 2026

    @DylanDylann
    Contributor

    Sorry for missing your earlier comment. I'd like to request a standard payment for this issue - $250. Although it doesn't require video evidence, the fix lies in a low-level layer, and it took time to investigate deeper and do related research on React Native to move it forward

    @mountiny Do you agree? ☝️

  14. mountiny commented on Jun 26, 2026

    @mountiny
    ContributorAuthor

    Yeah I think $250 here is appropriate @mallenexpensify

  15. mallenexpensify commented on Jun 26, 2026

    @mallenexpensify
    Contributor

    @DylanDylann paid, summary updated above. Thx.

  16. moved this from Done to SUBISSUE in [#whatsnext] #qualityon Jul 2, 2026
  17. quinthar commented on Jul 31, 2026

    @quinthar
    Contributor

    Approved $250 to @DylanDylann

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.DailyKSv2ExternalAdded to denote the issue can be worked on by a contributor

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions