Skip to content

Commit

Permalink
Fixed issue where batch would not be added to final list of vulns due…
Browse files Browse the repository at this point in the history
… to length mismatch
  • Loading branch information
ctevse committed Nov 3, 2023
1 parent 40ecfb2 commit a60854a
Showing 1 changed file with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public List<RawVulnerability> batchInsertRawVulnerability(List<RawVulnerability>
//Split vulns into batches for JDBC Insert
//TODO: Move the hardcoded value
for(List<RawVulnerability> batch: Lists.partition(vulns, 256)) {
int ignored = 0;
for(RawVulnerability vuln: batch) {
try {
pstmt.setString(1, vuln.getDescription());
Expand All @@ -84,12 +85,13 @@ public List<RawVulnerability> batchInsertRawVulnerability(List<RawVulnerability>
} catch (DateTimeParseException e) {
log.error("Failed to add {} to batch: {}", vuln.getCveId(), e.getMessage());
log.error("", e);
ignored++;
}
}

int[] results = pstmt.executeBatch();

if(results.length == vulns.size()){
if(results.length == (batch.size() - ignored) ){
for(int i = 0; i < vulns.size(); i++){
if(results[i] == Statement.SUCCESS_NO_INFO || results[i] == Statement.KEEP_CURRENT_RESULT || results[i] == Statement.CLOSE_CURRENT_RESULT) {
inserted.add(vulns.get(i));
Expand Down

0 comments on commit a60854a

Please sign in to comment.