fix(android): guard deconstructRegistration against null Registration#446
Open
niamh-coleman wants to merge 2 commits into
Open
fix(android): guard deconstructRegistration against null Registration#446niamh-coleman wants to merge 2 commits into
niamh-coleman wants to merge 2 commits into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Intercom.client().fetchLoggedInUserAttributes()returnsnullwhen no user is registered (OS killed the app, user not yet registered, etc.). The Android RN bridge passed thatnulldirectly intoIntercomHelpers.deconstructRegistration, which dereferenced it viaregistration.getEmail()and crashed the process withNullPointerException.WritableMapwhenregistrationisnull, matching the iOS bridge's nil-handling inIntercomAttributesBuilder.dictionaryForUserAttributes:(Obj-C nil-messaging makes its property reads safe and produces an emptyNSDictionary).Context
Reported via internal issue intercom/intercom#520691. Customer
thndr-app(app3437363) was seeing this as a fatal Android crash on production after background/lock cycles.Pre-existing bug, not a regression —
deconstructRegistrationhas 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)android/src/oldarch/IntercomModule.java:203-206android/src/newarch/IntercomModule.java:224-228Regression test
This PR also bootstraps a minimal JVM unit-test setup for the Android library (
android/build.gradlenow declaresjunit:junit:4.13.2andorg.mockito:mockito-core:5.11.0undertestImplementation, plus atestOptions { unitTests { ... } }block). A new test classandroid/src/test/java/com/intercom/reactnative/IntercomHelpersTest.javacovers:deconstructRegistration_returnsEmptyMap_whenRegistrationIsNull— direct regression guard for #520691. Against the pre-fix helper this test fails with the literal production NPECannot 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:
Test plan
:intercomreactnative:testDebugUnitTestpasses (2/2) against the patched helper; the null-case test fails as expected against the unpatched helper.Intercom.fetchLoggedInUserAttributes()from JS before anyloginUser*call on Android — should resolve to{}instead of crashing the app.Intercom.fetchLoggedInUserAttributes()immediately — should resolve to{}and not crash.Intercom.fetchLoggedInUserAttributes()still returns the email/userId map as before.Generated with Claude Code