Skip to content

fix(android): guard deconstructRegistration against null Registration#446

Open
niamh-coleman wants to merge 2 commits into
mainfrom
niamh/issue-520691-investigation
Open

fix(android): guard deconstructRegistration against null Registration#446
niamh-coleman wants to merge 2 commits into
mainfrom
niamh/issue-520691-investigation

Conversation

@niamh-coleman

@niamh-coleman niamh-coleman commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Intercom.client().fetchLoggedInUserAttributes() returns null when no user is registered (OS killed the app, user not yet registered, etc.). The Android RN bridge passed that null directly into IntercomHelpers.deconstructRegistration, which dereferenced it via registration.getEmail() and crashed the process with NullPointerException.
  • This patch returns an empty WritableMap when registration is null, matching the iOS bridge's nil-handling in IntercomAttributesBuilder.dictionaryForUserAttributes: (Obj-C nil-messaging makes its property reads safe and produces an empty NSDictionary).
  • One-line defensive guard in the helper — keeps the existing JS contract ("empty object when no logged-in user") and brings Android to parity with iOS.

Context

Reported via internal issue intercom/intercom#520691. Customer thndr-app (app 3437363) was seeing this as a fatal Android crash on production after background/lock cycles.

Pre-existing bug, not a regression — deconstructRegistration has never null-checked its argument across versions 9.8.0 → 10.0.2.

Affected code paths

  • android/src/main/java/com/intercom/reactnative/IntercomHelpers.java:249 (fixed)
  • Call sites that previously triggered the NPE:
    • android/src/oldarch/IntercomModule.java:203-206
    • android/src/newarch/IntercomModule.java:224-228

Regression test

This PR also bootstraps a minimal JVM unit-test setup for the Android library (android/build.gradle now declares junit:junit:4.13.2 and org.mockito:mockito-core:5.11.0 under testImplementation, plus a testOptions { unitTests { ... } } block). A new test class android/src/test/java/com/intercom/reactnative/IntercomHelpersTest.java covers:

  • deconstructRegistration_returnsEmptyMap_whenRegistrationIsNull — direct regression guard for #520691. Against the pre-fix helper this test fails with the literal production NPE Cannot invoke "io.intercom.android.sdk.identity.Registration.getEmail()" because "registration" is null; against the post-fix helper it passes.
  • deconstructRegistration_returnsBothFields_whenRegistrationIsFullyPopulated — happy-path guard so the fix can't accidentally regress map population.

Run locally with:

cd examples/example/android
./gradlew :intercomreactnative:testDebugUnitTest

Test plan

  • Automated: :intercomreactnative:testDebugUnitTest passes (2/2) against the patched helper; the null-case test fails as expected against the unpatched helper.
  • Manual: call Intercom.fetchLoggedInUserAttributes() from JS before any loginUser* call on Android — should resolve to {} instead of crashing the app.
  • Manual: kill the example app from recents, relaunch cold, call Intercom.fetchLoggedInUserAttributes() immediately — should resolve to {} and not crash.
  • Regression: with a logged-in user, Intercom.fetchLoggedInUserAttributes() still returns the email/userId map as before.
  • Parity: confirm iOS still returns an empty object for the same "no logged-in user" scenario.

Generated with Claude Code

niamh-coleman and others added 2 commits June 10, 2026 11:24
Intercom.client().fetchLoggedInUserAttributes() returns null when no
user is registered (e.g. after the OS kills the app). The Android
bridge passed that null straight into IntercomHelpers.deconstructRegistration,
which dereferenced it via registration.getEmail() and crashed the
process with NullPointerException.

Return an empty WritableMap on null, matching the iOS bridge's
nil-handling in IntercomAttributesBuilder.dictionaryForUserAttributes:.

Fixes intercom/intercom#520691

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…stration

Bootstraps a minimal Android JVM unit-test setup for the library
(JUnit 4 + Mockito 5) and adds a regression guard for the null
Registration crash in intercom/intercom#520691. The null-case test
fails with the exact production NPE message
("Cannot invoke ... Registration.getEmail() because registration is null")
against the pre-fix helper and passes after the fix.

Run with:
  cd examples/example/android && \
    ./gradlew :intercomreactnative:testDebugUnitTest

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.

1 participant