-
Notifications
You must be signed in to change notification settings - Fork 639
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
[ISSUE #3963] Method invocation 'getBytes' may produce 'NullPointerException'. #3971
Conversation
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.
LGTM~
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.
LGTM
@@ -60,7 +61,7 @@ public void handle(HttpExchange httpExchange) throws IOException { | |||
|
|||
try (OutputStream out = httpExchange.getResponseBody()) { | |||
WebHookConfig result = operation.queryWebHookConfigById(webHookConfig); // operating result | |||
out.write(JsonUtils.toJSONString(result).getBytes(Constants.DEFAULT_CHARSET)); | |||
out.write(Objects.requireNonNull(JsonUtils.toJSONString(result).getBytes(Constants.DEFAULT_CHARSET))); |
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.
I think this should be done:
out.write(Objects.requireNonNull(JsonUtils.toJSONString(result)).getBytes(Constants.DEFAULT_CHARSET));
@@ -73,7 +73,7 @@ public void handle(HttpExchange httpExchange) throws IOException { | |||
|
|||
try (OutputStream out = httpExchange.getResponseBody()) { | |||
List<WebHookConfig> result = operation.queryWebHookConfigByManufacturer(webHookConfig, pageNum, pageSize); // operating result | |||
out.write(JsonUtils.toJSONString(result).getBytes(Constants.DEFAULT_CHARSET)); | |||
out.write(Objects.requireNonNull(JsonUtils.toJSONString(result).getBytes(Constants.DEFAULT_CHARSET))); |
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.
same as above.
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.
Ok got it
@ZahaanMahajan you can merge the latest master branch code to fix the ci check error. |
I didn't get you. How to do that? |
pull apache:master to your local branch and push it to your remote master branch. |
Codecov Report
@@ Coverage Diff @@
## master #3971 +/- ##
=========================================
Coverage 14.25% 14.25%
Complexity 1320 1320
=========================================
Files 579 579
Lines 28943 28943
Branches 2794 2794
=========================================
Hits 4125 4125
Misses 24426 24426
Partials 392 392
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
Fixes #3963
Method invocation 'getBytes' may produce 'NullPointerException'.
In the modified code, Objects.requireNonNull() is applied to the return value of JsonUtils.toJSONString(result). If the result is null, a NullPointerException will be thrown immediately, preventing the subsequent invocation of getBytes().
By using Objects.requireNonNull(), it explicitly check for nullness and handle it in a more controlled manner, ensuring that it don't encounter unexpected null values during the execution of the code.