-
Notifications
You must be signed in to change notification settings - Fork 901
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
[Bug] Fix internal server error when unexpected json inputs are sent to Bookkeeper HTTP Services #3914
Conversation
Forked Repo PR where test results passed: Apurva007#1 |
@hangc0276 / @BewareMyPower Please can you help review the PR. |
Map<String, Object> configMap = JsonUtil.fromJson(requestBody, HashMap.class); | ||
Boolean forceMajor = (Boolean) configMap.getOrDefault("forceMajor", null); | ||
Boolean forceMinor = (Boolean) configMap.getOrDefault("forceMinor", null); | ||
Map<String, String> configMap = JsonUtil.fromJson(requestBody, HashMap.class); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the requestBody
doesn't pass a String, the JsonUtil.fromJson will throw an exception.
Would you please add a test for this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hangc0276 Thanks for the review. I will add the respective tests.
bede630
to
c95cc34
Compare
c95cc34
to
3ff05b8
Compare
… invalid values in json input
3ff05b8
to
c034c22
Compare
@hangc0276 I have made the suggested changes. Please can you review again when you get a chance. |
@hangc0276 Please can you help re-review this PR when you get a chance. |
Object forceMinorObj = configMap.getOrDefault("forceMinor", null); | ||
boolean forceMajor = false, forceMinor = false; | ||
if (forceMajorObj instanceof Boolean) { | ||
forceMajor = (Boolean) forceMajorObj; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should throw an error if it is not a boolean, otherwise the result is unpredictable
Descriptions of the changes in this PR:
This PR fixes the internal server error when the following are executed with unexpected json inputs via the REST API:
The reason this error occurs is because the code is trying to force cast inputs it receives as Json to Boolean without checking the type.
The code change is to make this conversion safer.
Motivation
Fixes #3845
Changes
Modified the code to perform a safer boolean conversion when trying to find the values in the JSON payload.
Master Issue: #3845