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

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

Closed
Marcono1234 opened this issue Aug 29, 2020 · 0 comments · Fixed by #2167
Closed

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

Marcono1234 opened this issue Aug 29, 2020 · 0 comments · Fixed by #2167
Labels

Comments

@Marcono1234
Copy link
Collaborator

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
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant