Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

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

Open
#1,527 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
java
Domain
backend

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.

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");
}
Dominant language
Java
Stars
438
Forks
117
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from mapbox/mapbox-java

All issues in mapbox/mapbox-java

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.