Skip to content

Commit

Permalink
Fixed a bug in which a NullptrException was thrown when trying to rea…
Browse files Browse the repository at this point in the history
…udit a cvr that wasn't previously audited.
  • Loading branch information
vteague committed Aug 3, 2024
1 parent 8894b9c commit 9703b08
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -232,13 +232,14 @@ public static boolean reaudit(final CountyDashboard cdb,
final String comment) {

LOGGER.info("[reaudit] cvr: " + cvr.toString());
final CVRAuditInfo cai =
Persistence.getByID(cvr.id(), CVRAuditInfo.class);
final CastVoteRecord oldAcvr = cai.acvr();
if (null == oldAcvr) {

// VT: If this cvr has not been audited before, I believe cai will be null.
final CVRAuditInfo cai = Persistence.getByID(cvr.id(), CVRAuditInfo.class);
if (cai == null || cai.acvr() == null) {
LOGGER.error("can't reaudit a cvr that hasn't been audited");
return false;
}
final CastVoteRecord oldAcvr = cai.acvr();

final Integer former_count = unaudit(cdb, cai);
LOGGER.debug("[reaudit] former_count: " + former_count.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -456,19 +456,19 @@ void testACVRUploadAndStorage() {
// Expected error messages for malformed upload cvrs.
String malformedACVRMsg = "malformed audit CVR upload";

testErrorResponse(240512L, pluralityIRVAsJson, malformedACVRMsg);
testErrorResponseAndNoMatchingCvr(240512L, pluralityIRVAsJson, malformedACVRMsg);

// Fifth test: upload a vote with IRV choices that are not among the valid candidates. This
// should cause an error.
testErrorResponse(240513L, wrongCandidateNamesIRVAsJson, malformedACVRMsg);
testErrorResponseAndNoMatchingCvr(240513L, wrongCandidateNamesIRVAsJson, malformedACVRMsg);

// Sixth test: upload a vote with IDs that do not correspond properly to the expected CVR.
// This should cause an error.
testErrorResponse(240514L, IRVWithInconsistentIDsAsJson, malformedACVRMsg);
testErrorResponseAndNoMatchingCvr(240514L, IRVWithInconsistentIDsAsJson, malformedACVRMsg);

// Seventh test: upload a vote that has typos preventing json deserialization. This should
// cause an error.
testErrorResponse(240515L, IRVJsonDeserializationFail, malformedACVRMsg);
testErrorResponseAndNoMatchingCvr(240515L, IRVJsonDeserializationFail, malformedACVRMsg);

// Eighth test: upload a reaudit ballot.
// Check that the new data successfully replaces the prior upload.
Expand All @@ -484,7 +484,7 @@ void testACVRUploadAndStorage() {
testPreviousAreReaudited(240509L, "1-1-1", List.of("Alice","Chuan"), 2, 2);

// Tenth test: try to "re-"audit something that has not previously been successfully audited. Should throw an error.
testErrorResponse(240515L, IRVReauditNoPriorUpload, "");
testErrorResponseAndNoMatchingCvr(240515L, IRVReauditNoPriorUpload, "CVR has not previously been audited");
}
}

Expand Down Expand Up @@ -585,7 +585,7 @@ private void testPreviousAreReaudited(final long CvrId, final String expectedImp
* @param CvrAsJson The upload cvr, as a json string.
* @param expectedError The expected error message.
*/
private void testErrorResponse(final long CvrId, final String CvrAsJson, final String expectedError) {
private void testErrorResponseAndNoMatchingCvr(final long CvrId, final String CvrAsJson, final String expectedError) {
final Request request = new SparkRequestStub(CvrAsJson, new HashSet<>());
String errorBody = "";

Expand Down

0 comments on commit 9703b08

Please sign in to comment.