WordPress-FluxC-Android icon indicating copy to clipboard operation
WordPress-FluxC-Android copied to clipboard

NullPointerException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkNotNullParame...

Open sentry-io[bot] opened this issue 3 years ago • 6 comments

Sentry Issue: WOOCOMMERCE-ANDROID-4M2

NullPointerException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkNotNullParameter, parameter <this>
    at kotlin.text.StringsKt__StringsKt.startsWith
    at kotlin.text.StringsKt__StringsKt.startsWith$default(Strings.kt:835)
    at kotlin.text.StringsKt.startsWith$default
    at kotlin.text.StringsKt.startsWith$default
    at kotlin.text.StringsKt.startsWith$default
...
(33 additional frame(s) were not displayed)

sentry-io[bot] avatar Aug 12 '22 18:08 sentry-io[bot]

Crash is happening when stripping order metadata here. Additional stack trace:

 at org.wordpress.android.fluxc.network.rest.wpcom.wc.order.OrderMappingConst.isInternalAttribute$woocommerce_release(OrderMappingConst.kt:9)
    at org.wordpress.android.fluxc.network.rest.wpcom.wc.order.StripOrderMetaData$invoke$1.invoke(StripOrderMetaData.kt:30)
    at org.wordpress.android.fluxc.network.rest.wpcom.wc.order.StripOrderMetaData$invoke$1.invoke(StripOrderMetaData.kt:30)
    at org.wordpress.android.fluxc.network.rest.wpcom.wc.order.StripOrderMetaData$invoke$1.invoke(StripOrderMetaData.kt:30)
    at org.wordpress.android.fluxc.network.rest.wpcom.wc.order.StripOrderMetaData$invoke$1.invoke(StripOrderMetaData.kt:30)
    at kotlin.sequences.FilteringSequence$iterator$1.calcNext(Sequences.kt:171)
    at kotlin.sequences.FilteringSequence$iterator$1.hasNext(Sequences.kt:194)
    at kotlin.sequences.TransformingSequence$iterator$1.hasNext(Sequences.kt:214)
    at kotlin.sequences.FilteringSequence$iterator$1.calcNext(Sequences.kt:169)
    at kotlin.sequences.FilteringSequence$iterator$1.hasNext(Sequences.kt:194)

Update: the crash appears to happen when calling isInternalAttribute here which suggests the WCMetaData.key is null even though it's defined as non-null. Perhaps this GSON limitation is the problem?

nbradbury avatar Aug 12 '22 18:08 nbradbury

Oh, interesting, thanks for the ping @nbradbury. We verified this same problem during the Product Add-ons project a year ago, some metadata does show up with invalid data like null keys sometimes. Considering that any Woo plugin can generate metadata, I believe it would be best if we always expect the worst and don't mark anything coming from the API as non-null, and use the Kotlin null safety features to filter out invalid metadata info. WDYT?

ThomazFB avatar Aug 12 '22 19:08 ThomazFB

always expect the worst and don't mark anything coming from the API as non-null, and use the Kotlin null safety features to filter out invalid metadata info. WDYT?

That would work but it sure complicates things! I'm wondering if setting a default value for the WCMetaData.key would help, eg: @SerializedName("key") val key: String = ""?

nbradbury avatar Aug 12 '22 19:08 nbradbury

I think it's worth trying. The only problem I see is that the issue you posted mentions that default values are also getting ignored by Gson. Maybe they already fixed it?

ThomazFB avatar Aug 12 '22 19:08 ThomazFB

Well 💩 . I read somewhere that the constructor isn't called when the GSON key doesn't exist and was hoping a default value would fix it, but reading further I believe you're right - the initialization is skipped entirely. What a mess.

nbradbury avatar Aug 12 '22 19:08 nbradbury

Yeah, sounds like we're in a bad situation about trusting the Gson lib 😓, I decided to tackle this fix as we discussed here in this PR: https://github.com/wordpress-mobile/WordPress-FluxC-Android/pull/2500

Let me know if you think this works. Thanks!

ThomazFB avatar Aug 13 '22 01:08 ThomazFB