[services-geojson] NullPointerException in Feature.addXxxProperty() or getXxxProperty() methods
還沒有人認領這個 Issue。
- 主要語言
- Java
- 星號
- 438
- 分支
- 117
- PR 合併指標
- 30 天內沒有已合併 PR
描述
All methods like addStringProperty(), addNumberProperty(), getStringProperty()… don’t guard against a null properties field.
The “guard” is at a higher level, as using Feature static factory methods ensure that the properties field is never null.
However Feature.GsonTypeAdapter.read() directly calls the Feature constructor which doesn’t prevent a null properties field. So for example, if someone calls FeatureCollection.fromJson() which contains a feature that has a null properties field, it will be decoded by the GsonAdapter and then calling addStringProperty() on this feature will crash.
Small code sample to demonstrate that
public void addPropertyCrash() {
final String json = "{" +
"\"type\": \"FeatureCollection\"," +
"\"features\": [" +
"{" +
"\"type\": \"Feature\"," +
"\"properties\": null," +
"\"geometry\": null" +
"}" +
"]" +
"}";
FeatureCollection actual = FeatureCollection.fromJson(json);
actual.features().get(0).addStringProperty("key", "value");
}
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
從 FeatureCollection.fromJson() 呼叫到的 Feature.GsonTypeAdapter.read() 開始,檢查 null 的 properties 欄位如何到達 Feature.addStringProperty() 及相關的 add/get 方法。驗證提供的 FeatureCollection JSON 範例在新增屬性時不再導致 NullPointerException。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- java
- 領域
- backend
- Issue 類型
- 缺陷
- 難度
- 2/5
- 預估耗時
- 1-3 小時
- 活躍度
- 停滯
- 描述清晰度
- 基本清楚
- 新手友好度
- 45/100