[services-geojson] NullPointerException in Feature.addXxxProperty() or getXxxProperty() methods
Nessuno ha ancora preso questa issue.
- Lingua principale
- Java
- Stelle
- 438
- Fork
- 117
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
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");
}
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia da Feature.GsonTypeAdapter.read(), che viene raggiunto tramite FeatureCollection.fromJson(), e analizza come un campo properties nullo raggiunge Feature.addStringProperty() e i relativi metodi add/get. Verifica che l’esempio JSON di FeatureCollection fornito non causi più una NullPointerException quando viene aggiunta una proprietà.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- java
- Ambito
- backend
- Tipo di issue
- Bug
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 45/100