mapbox / mapbox/mapbox-java

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

Đang mở
#1,527 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Ngôn ngữ chính
Java
Star
438
Fork
117
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

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");
}
```

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu từ Feature.GsonTypeAdapter.read(), được gọi thông qua FeatureCollection.fromJson(), và kiểm tra cách một trường properties null đi tới Feature.addStringProperty() cùng các phương thức add/get liên quan. Xác minh rằng ví dụ JSON FeatureCollection được cung cấp không còn gây ra NullPointerException khi một thuộc tính được thêm vào.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
java
Lĩnh vực
backend
Loại issue
Lỗi
Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
45/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.