Skip to content

JsonObject.entrySet() Entry.setValue(...) does not prevent null values #1771

Closed

Description

@Marcono1234

The Map.Entry objects in the Set returned by JsonObject.entrySet() do not validate the value passed to their Entry.setValue(...) method, allowing Java nulls. This can cause runtime exceptions when the user of the JsonObject later expects that the values returned by JsonObject are never null:

JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("test", 1);
jsonObject.entrySet().iterator().next().setValue(null);

System.out.println("has=" + jsonObject.has("test"));
jsonObject.getAsJsonPrimitive("test").toString(); // NullPointerException

The Map.Entry objects should instead throw a NullPointerException when their setValue(...) method is called with null (as permitted by the documentation).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions