mparticle-android-sdk icon indicating copy to clipboard operation
mparticle-android-sdk copied to clipboard

FilteredMParticleUser.getConsentState() returns null even though the interface function has @NonNull

Open gpunto opened this issue 1 year ago • 0 comments

Hello!

I'm using ConsentState.withConsentState(user.consentState) to create a builder to update consent in onUserIdentified. However, when user is FilteredMParticleUser this will crash because consentState returns null. Partial stacktrace:

java.lang.NullPointerException: Attempt to invoke virtual method 'java.util.Map com.mparticle.consent.ConsentState.getGDPRConsentState()' on a null object reference
	at com.mparticle.consent.ConsentState$Builder.<init>(SourceFile:15)
	at com.mparticle.consent.ConsentState$Builder.<init>(SourceFile:1)
	at com.mparticle.consent.ConsentState.withConsentState(SourceFile:1)

This should likely be caught at compile-time, since ConsentState.withConsentState requires a non-null ConsentState. However, the problem is that MParticleUser.getConsentState() is annotated as NonNull, so the Kotlin compiler trusts the annotation, while the FilteredMParticleUser implementation returns null.

For reference, I was taking this kit as an example implementation.

gpunto avatar Feb 14 '24 12:02 gpunto