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).
The Map.Entry objects in the Set returned by
JsonObject.entrySet()do not validate the value passed to theirEntry.setValue(...)method, allowing Javanulls. This can cause runtime exceptions when the user of the JsonObject later expects that the values returned by JsonObject are nevernull:The Map.Entry objects should instead throw a NullPointerException when their
setValue(...)method is called withnull(as permitted by the documentation).