Skip to content

Handle null consent state during appsflyer kit init when GDPR is enabled#120

Open
ankitsingh08 wants to merge 1 commit into
mparticle-integrations:mainfrom
ankitsingh08:fix-gdpr-null-consent-init
Open

Handle null consent state during appsflyer kit init when GDPR is enabled#120
ankitsingh08 wants to merge 1 commit into
mparticle-integrations:mainfrom
ankitsingh08:fix-gdpr-null-consent-init

Conversation

@ankitsingh08
Copy link
Copy Markdown

Background

  • In mParticle logs, this surfaced as:
    • org.json.JSONException: Value null of type org.json.JSONObject$1 cannot be converted to JSONObject
  • This issue started surfacing after GDPR was enabled for the AppsFlyer kit configuration.
  • During kit initialization, AppsFlyerKit.onKitCreate() reads currentUser?.consentState, but consent may legitimately still be null at that point if no consent state has been set yet.
  • In the GDPR-enabled path, setConsent() proceeded into consent parsing and attempted to parse consentState.toString() even when consentState was null.
  • The crash sequence was:
    • AppsFlyerKit.onKitCreate() calls setConsent(currentUser?.consentState)
    • GDPR is enabled, so the method does not return early
    • parseToNestedMap(consentState.toString()) is invoked with a null consent state
    • JSON parsing fails before any later consent update can be applied
  • This is especially problematic because initialization can happen before consent is available, so the kit should tolerate a missing consent state and continue using configured default consent values until real consent arrives.

What Has Changed

  • Guarded the GDPR consent parsing path so mapped consent values are only read when a real ConsentState is present.
  • Preserved the existing default AppsFlyer consent fallback behavior when GDPR is enabled but consent has not yet been populated.
  • Added a regression test covering the GDPR-enabled null-consent path to verify we do not crash and that defaults are still applied.

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 testDebugUnitTest --tests com.mparticle.kits.AppsflyerKitTests
  • The fix is intentionally minimal and additive:
    • when consent is not yet available during initialization, the kit now falls back to configured default GDPR consent values
    • when consent is later provided, the existing onConsentStateUpdated() flow continues to apply mapped consent values as before

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