[services-geojson] NullPointerException in Feature.addXxxProperty() or getXxxProperty() methods
- Dominant language
- Java
- Stars
- 438
- Forks
- 117
- PR merge metrics
- No merged PRs in 30d
Description
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");
}
```
Contributor guide
Research direction
Start at Feature.GsonTypeAdapter.read(), which is reached through FeatureCollection.fromJson(), and inspect how a null properties field reaches Feature.addStringProperty() and the related add/get methods. Verify that the provided FeatureCollection JSON example no longer causes a NullPointerException when a property is added.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100