Uncaught NPE in siteResponseToSiteModel when WP.com returns blogging_prompts_settings with null reminders_days/reminders_time
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 76/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 冷清
- 领域
- api, mobile-dev
调研方向
从 libs/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/site/SiteRestClient.kt 中的 siteResponseToSiteModel() 开始,重点查看 blogging_prompts_settings 块。检查 reminders_days 和 reminders_time 的 null 处理,然后添加回归测试覆盖:将每个子字段设为 null,并确认 site 解析能够在不抛出异常的情况下完成。使用现有的 SiteWPComRestResponse.java 字段声明来了解 response 的结构。
由索引模型根据 Issue 内容生成。
描述
Summary
SiteRestClient.siteResponseToSiteModel()parsesblogging_prompts_settingsfrom the WP.com sites response and dereferences two sub-fields without a null guard. If the server returnsblogging_prompts_settingsas a non-null object but withreminders_daysorreminders_timenull/absent, the parse throws an uncaughtNullPointerExceptionand the entire site fetch fails.- Both fields are plain unannotated Java fields (Kotlin platform types), so the compiler inserts no caller-side null check — same mechanism as the null-
URLcrash currently live in production (SentryJETPACK-ANDROID-1JAS). - Latent today — no production occurrences yet — but reachable:
blogging_prompts_settingsships underoptions, which is in thefields=allowlist, and there is zero test coverage of this path.
Root cause
In libs/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/site/SiteRestClient.kt, inside siteResponseToSiteModel() (the from.options.blogging_prompts_settings?.let { ... } block, ~L1131–1150). The ?.let guards the parent object being null; it does nothing for the sub-fields:
1. reminders_days — null Map dereference (~L1137–1143) ❌
site.setIsBloggingReminderOnMonday(it.reminders_days["monday"] ?: false)
// ... through Sunday
it.reminders_days["monday"] desugars to it.reminders_days.get("monday"). The ?: false operates on the return value of get, not the receiver — so a null reminders_days map NPEs on the .get call. These seven lines are not inside any try/catch.
reminders_days is declared public Map<String, Boolean> reminders_days; (SiteWPComRestResponse.java:107) — no annotation, no @SerializedName, no custom deserializer. Stock Gson leaves it null when the key is absent or its value is JSON null.
2. reminders_time — null String dereference (~L1144–1149) ❌
try {
site.bloggingReminderHour = it.reminders_time.split(".")[0].toInt()
site.bloggingReminderMinute = it.reminders_time.split(".")[1].toInt()
} catch (ex: NumberFormatException) {
AppLog.e(API, "Received malformed blogging reminder time: " + ex.message)
}
it.reminders_time.split(".") throws NPE on a null reminders_time. The surrounding try catches only NumberFormatException — NullPointerException is not a subclass of it (NFE → IllegalArgumentException; NPE → RuntimeException), so the NPE escapes the catch. reminders_time is public String reminders_time; (SiteWPComRestResponse.java:108), same platform-type/Gson story.
The crash propagates uncaught out of siteResponseToSiteModel() to its callers (fetchSite, fetchSites, and the site-feature path).
Why it can happen
The "the server always sends a complete blogging_prompts_settings object" assumption is unverified and unenforced — no @NonNull, no test, no fixture. We have direct, recent production proof that this exact endpoint violates field-presence assumptions: site.url = from.URL reads an identically-unannotated field and just started returning null in production (Sentry JETPACK-ANDROID-1JAS, ~1,300 crashes / ~180 users in the first ~7.5h). The method itself already distrusts this object's contents (the NumberFormatException catch on reminders_time) — it just doesn't guard the fields' presence. /me/sites/ and /sites/$site/ are also documented in-method as returning different shapes for the same fields.
Evidence
Adversarially validated by three independent reviewers; two reproduced the exact exceptions with a standalone kotlinc repro of the platform-type + deref pattern:
reminders_daysnull →java.lang.NullPointerException: Cannot invoke "java.util.Map.get(Object)" because "it.reminders_days" is nullreminders_timenull →java.lang.NullPointerException: reminders_time must not be null(KotlinIntrinsics.checkNotNullExpressionValueemitted beforesplit)
Bytecode confirmed the ?: false Elvis sits on the get result, after the null receiver has already been invoked.
Fix
Null-safe both dereferences (the surrounding code already treats this object as untrusted):
// reminders_days — all seven day lines:
site.setIsBloggingReminderOnMonday(it.reminders_days?.get("monday") ?: false)
// reminders_time — safe-call before split (or broaden the catch to cover NPE/IndexOutOfBounds):
it.reminders_time?.split(".")?.let { parts ->
try {
site.bloggingReminderHour = parts[0].toInt()
site.bloggingReminderMinute = parts[1].toInt()
} catch (ex: NumberFormatException) {
AppLog.e(API, "Received malformed blogging reminder time: " + ex.message)
}
}
A regression test that feeds siteResponseToSiteModel a blogging_prompts_settings with each sub-field null would lock this in — the path currently has no coverage.
Related
- Live null-
URLincident (same root pattern, different field): SentryJETPACK-ANDROID-1JAS. TheURLcase is being addressed server-side (it's the only field that crashes thejava.net.URIparser); these two are the remaining client-side null-deref siblings in the same parse method.
Found while triaging the null-URL crash.
- 主要语言
- Kotlin
- 星标
- 3.2k
- 派生
- 1.4k
- 平均合并
- 1 天 4 小时
- 30 天内合并 PR
- 100
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
wordpress-mobile/WordPress-Android 的其他 Issue
-
[Pri] Low [Type] Enhancement Good First Issue Media
难度 2/5 1-3 小时 新手友好度 72/100
wordpress-mobile/WordPress-Android#16212 · 2 条评论 ·
维护者通常 1 天内回复
-
[Type] Bug Posting/Editing
难度 1/5 1 小时以内 新手友好度 68/100
wordpress-mobile/WordPress-Android#11342 · 1 条评论 ·
维护者通常 1 天内回复
-
[Status] Stale [Type] Task Documentation
难度 2/5 1-3 小时 新手友好度 62/100
wordpress-mobile/WordPress-Android#10979 · 1 条评论 ·
维护者通常 1 天内回复
-
[Status] Stale [Type] Enhancement
难度 2/5 1-3 小时 新手友好度 64/100
wordpress-mobile/WordPress-Android#10102 · 2 条评论 ·
维护者通常 1 天内回复
-
[Type] Enhancement
难度 5/5 一周以上 新手友好度 15/100
wordpress-mobile/WordPress-Android#23522 · 1 条评论 ·
维护者通常 1 天内回复
查看 wordpress-mobile/WordPress-Android 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 65/100
aphtech/brailleblaster#210 ·
维护者通常 1 天内回复
-
bug registro
难度 2/5 1-3 小时 新手友好度 72/100
-
Accounts tab: row separator doesn't align with account name when account type icons are off可能已有人在做 @azimul-kabir 今天认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 84/100
azimul-kabir/actua#1780 ·
维护者通常 1 天内回复
-
enhancement needs-triage
难度 2/5 1-3 小时 新手友好度 70/100
facebook/facebook-android-sdk#1423 ·
-
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复