Open sentry-io[bot] opened 2 years ago
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?
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?
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 = ""
?
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?
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.
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!
Sentry Issue: WOOCOMMERCE-ANDROID-4M2