[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