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

Handle null input in JsonOps.convertTo #99

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Papierkorb2292
Copy link

The current implementation of JsonOps.convertTo throws a null pointer exception when input is null by calling input.getAsJsonPrimitive() without checking for null. Instead, the implementation only checks whether input is an implementation of JsonNull. This is problematic because some of the other methods in JsonOps replace a JsonNull instance with null when returning it, which makes it possible that input is null instead of a JsonNull instance. An example of such a method is JsonOps.getMapValues.

This is an issue with the implementation of convertTo and not just a problem with call sites elsewhere, because convertTo also uses getMapValues when converting maps and it recursively calls convertTo on the returned map values, which means an input like {"value": null} is also going to throw an error even though it is a valid JsonObject instance.

This pull request adds a null check besides the instanceof check for JsonNull, such that a null input value and a value of type JsonNull are handled the same in JsonOps.convertTo.

This also fixes #62

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

Successfully merging this pull request may close these issues.

JsonOps.convertTo explodes on JsonNulls
1 participant