Skip to content

Handle legacy persisted domain mappings safely#703

Open
ankitsingh08 wants to merge 2 commits into
mParticle:mainfrom
ankitsingh08:fix-domainmapping-legacy-json
Open

Handle legacy persisted domain mappings safely#703
ankitsingh08 wants to merge 2 commits into
mParticle:mainfrom
ankitsingh08:fix-domainmapping-legacy-json

Conversation

@ankitsingh08
Copy link
Copy Markdown

Background

  • This issue appears to have been introduced after #588, where persisted DomainMapping parsing began expecting overridesSubdirectory to always be present.
  • Users upgrading from older Android SDK versions can still have persisted UploadSettings / NetworkOptions JSON containing legacy domainMappings entries that do not include overridesSubdirectory.
  • In mParticle logs, this surfaced as:
    • No value for overridesSubdirectory
    • Attempt to invoke virtual method 'com.mparticle.networking.DomainMapping com.mparticle.networking.DomainMapping$Builder.build()' on a null object reference
  • The current parser expected overridesSubdirectory to always be present, which caused legacy entries to fail parsing.
  • In the persisted NetworkOptions flow, that parse failure could produce a null DomainMapping.Builder, and the subsequent .build() call could trigger a null object reference crash.
  • Because these values are read from persisted upload settings, affected users could continue seeing repeated failures until the stale rows were replaced.

What Has Changed

  • Updated DomainMapping JSON parsing to use a backward-compatible default of false when overridesSubdirectory is missing.
  • Hardened NetworkOptions parsing so invalid persisted domain mapping entries are skipped instead of crashing the entire parse flow.
  • Added regression tests covering:
    • legacy persisted DomainMapping JSON without overridesSubdirectory
    • NetworkOptions JSON with one valid persisted mapping and one invalid mapping

Screenshots/Video

  • Not applicable for this change.

Checklist

  • I have performed a self-review of my own code.
  • I have made corresponding changes to the documentation.
  • I have added tests that prove my fix is effective or that my feature works.
  • I have tested this locally.

Additional Notes

  • Local validation run:
    • ./gradlew :android-core:testDebugUnitTest --tests com.mparticle.networking.NetworkOptionsTest
  • The fix is intentionally minimal and additive to preserve backward compatibility and avoid API changes.

@ankitsingh08 ankitsingh08 requested a review from a team as a code owner May 18, 2026 19:43
@cursor
Copy link
Copy Markdown

cursor Bot commented May 18, 2026

PR Summary

Medium Risk
Touches persisted NetworkOptions/DomainMapping JSON parsing used for network routing; while the change is defensive, mistakes here could affect endpoint selection or silently drop mappings.

Overview
Improves resilience when deserializing persisted NetworkOptions/DomainMapping JSON.

DomainMapping now treats missing overridesSubdirectory as false (backward compatible with legacy stored values), and NetworkOptions.withNetworkOptions skips and logs invalid domain-mapping entries instead of calling .build() on a null builder.

Adds regression tests covering legacy mappings without overridesSubdirectory and mixed valid/invalid persisted mappings.

Reviewed by Cursor Bugbot for commit 46d8070. Bugbot is set up for automated code reviews on this repo. Configure here.

@sonarqubecloud
Copy link
Copy Markdown

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