Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Canivek opened this issue Jan 10, 2023 · 0 comments

Comments

@Canivek
Copy link

Canivek commented Jan 10, 2023

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");
}
@Canivek Canivek changed the title NullPointerException in Feature.addXxxProperty() or getXxxProperty() methods [services-geojson] NullPointerException in Feature.addXxxProperty() or getXxxProperty() methods Jan 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant