mapbox / mapbox/mapbox-java

[services-geojson] NullPointerException in Feature.addXxxProperty() or getXxxProperty() methods

オープン
#1,527 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

主要言語
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");
}
```

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. 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

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。