Skip to content

Commit

Permalink
refactor out of memory check in separate function
Browse files Browse the repository at this point in the history
  • Loading branch information
zahidblackduck committed Jan 30, 2025
1 parent 7fe206b commit 435951a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ public static ExitCodeType getWinningExitCodeType(ExitCodeType first, ExitCodeTy
} else if (second.isSuccess()) {
return first;
} else {
if (first.priority < second.priority) {
if (first.getPriority() < second.getPriority()) {
return first;
} else if (second.priority < first.priority) {
} else if (second.getPriority() < first.getPriority()) {
return second;
} else {
return (first.getExitCode() < second.getExitCode()) ? first : second;
Expand All @@ -80,4 +80,6 @@ public boolean isSuccess() {
public String getDescription() {
return description;
}

public double getPriority() { return priority; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,7 @@ public DetectorToolResult performDetectors(
List<DetectorDirectoryReport> reports = new DetectorReporter().generateReport(evaluation);
DetectorToolResult toolResult = publishAllResults(reports, directory, projectDetector, requiredDetectors, requiredAccuracyTypes);

boolean outOfMemoryIssueFound = detectorIssuePublisher.hasOutOfMemoryIssue(reports);

if (outOfMemoryIssueFound) {
logger.error("Detected an issue: EXECUTABLE_TERMINATED_LIKELY_OUT_OF_MEMORY");
exitCodePublisher.publishExitCode(ExitCodeType.FAILURE_OUT_OF_MEMORY, "Executable terminated likely due to out of memory.");
}
checkAndHandleOutOfMemoryIssue(reports);

//Completed.
logger.debug("Finished running detectors.");
Expand All @@ -122,6 +117,13 @@ public DetectorToolResult performDetectors(
return toolResult;
}

private void checkAndHandleOutOfMemoryIssue(List<DetectorDirectoryReport> reports) {
if (detectorIssuePublisher.hasOutOfMemoryIssue(reports)) {
logger.error("Detected an issue: EXECUTABLE_TERMINATED_LIKELY_OUT_OF_MEMORY");
exitCodePublisher.publishExitCode(ExitCodeType.FAILURE_OUT_OF_MEMORY, "Executable terminated likely due to out of memory.");
}
}

private DetectorToolResult publishAllResults(
List<DetectorDirectoryReport> reports,
File directory,
Expand Down

0 comments on commit 435951a

Please sign in to comment.