-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
[Enhancement] Profile enhance #52779
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: before-Sunrise <[email protected]>
Signed-off-by: before-Sunrise <[email protected]>
Signed-off-by: before-Sunrise <[email protected]>
Signed-off-by: before-Sunrise <[email protected]>
return results; | ||
|
||
} | ||
|
||
public static long getTotalQueriesCount() { | ||
return TOTAL_QUERIES.size(); | ||
} |
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.
The most risky bug in this code is:
If TOTAL_QUERIES.pollFirst()
returns null
because the deque is empty or has concurrent modifications, a NullPointerException might occur when calling head.getQueryId()
.
You can modify the code like this:
private static void removeExpiredQueryDetails() {
long deleteTime = getCurrentTimeNS() - Config.query_detail_cache_time_nanosecond;
while (!TOTAL_QUERIES.isEmpty()) {
QueryDetail head = TOTAL_QUERIES.peekFirst();
if (head != null && head.getEventTime() < deleteTime) {
TOTAL_QUERIES.pollFirst();
QUERY_MAP.remove(head.getQueryId());
} else {
break;
}
}
}
private static class ProfileRequest { | ||
List<String> profileIds; | ||
} | ||
} No newline at end of file |
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.
The most risky bug in this code is:
Not handling potential NullPointerException when accessing profileRequest.profileIds
.
You can modify the code like this:
public void execute(BaseRequest request, BaseResponse response) throws DdlException {
String jsonStr = request.getContent();
Gson gson = new Gson();
ProfileRequest profileRequest;
try {
Type type = new TypeToken<ProfileRequest>() {}.getType();
profileRequest = gson.fromJson(jsonStr, type);
// Add a null check for profileRequest to avoid NPE
if (profileRequest == null || profileRequest.profileIds == null || profileRequest.profileIds.isEmpty()) {
response.getContent().append("profileIds cannot be empty");
sendResult(request, response, HttpResponseStatus.BAD_REQUEST);
return;
}
} catch (Exception e) {
response.getContent().append("not valid parameter");
sendResult(request, response, HttpResponseStatus.BAD_REQUEST);
return;
}
List<String> profileIds = profileRequest.profileIds;
List<String> profiles = QueryDetailQueue.getQueryProfilesByQueryIds(profileIds);
String jsonString = gson.toJson(profiles);
response.getContent().append(jsonString);
sendResult(request, response);
}
This fix ensures that if gson.fromJson
returns null
, the method will handle it properly by attaching an error message and returning an appropriate HTTP response.
Signed-off-by: before-Sunrise <[email protected]>
Signed-off-by: before-Sunrise <[email protected]>
Quality Gate passedIssues Measures |
[Java-Extensions Incremental Coverage Report]✅ pass : 0 / 0 (0%) |
[BE Incremental Coverage Report]✅ pass : 0 / 0 (0%) |
[FE Incremental Coverage Report]✅ pass : 46 / 46 (100.00%) file detail
|
Why I'm doing:
What I'm doing:
Fixes #issue
What type of PR is this:
Does this PR entail a change in behavior?
If yes, please specify the type of change:
Checklist:
Bugfix cherry-pick branch check: