Skip to content

Commit

Permalink
Added log statements for debugging size errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ctevse committed Nov 4, 2023
1 parent b1ae1a6 commit 3245dac
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion crawler/src/main/java/edu/rit/se/nvip/CrawlerMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ private void insertRawCVEsAndPrepareMessage(HashMap<String, ArrayList<RawVulnera
// Sends a JSON object with an array of CVE IDs that require reconciliation
Gson gson = new Gson();

String cveArray = gson.toJson(insertedVulns.stream().map(RawVulnerability::getCveId).peek(log::info).toList());
String cveArray = gson.toJson(insertedVulns.stream().map(RawVulnerability::getCveId).peek(vuln -> log.info(vuln)).toList());
Map<String, String> messageBody = new HashMap<>();
messageBody.put("cves", cveArray);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +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;
List<RawVulnerability> submittedVulns = new ArrayList<>();
for(RawVulnerability vuln: batch) {
try {
pstmt.setString(1, vuln.getDescription());
Expand All @@ -82,23 +82,23 @@ public List<RawVulnerability> batchInsertRawVulnerability(List<RawVulnerability>
pstmt.setString(7, vuln.getSourceType());
pstmt.setString(8, vuln.getParserType());
pstmt.addBatch();
submittedVulns.add(vuln);
} 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 == (batch.size() - ignored) ){
for(int i = 0; i < batch.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));
} else {
log.info("Failed to insert {}: {}", vulns.get(i).getCveId(), results[i]);
}
log.info("Size of submittedVulns: {} - Size of results: {}", submittedVulns.size(), results.length);
int i = 0;
for(RawVulnerability vuln: submittedVulns) {
if (results[i] == Statement.SUCCESS_NO_INFO || results[i] == Statement.KEEP_CURRENT_RESULT || results[i] == Statement.CLOSE_CURRENT_RESULT) {
inserted.add(vuln);
} else {
log.info("Failed to insert {}: {}", vulns.get(i).getCveId(), results[i]);
}
i++;
}
pstmt.clearBatch();
}
Expand Down

0 comments on commit 3245dac

Please sign in to comment.