Skip to content
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

invoice: fix NPE in DefaultInvoiceDao #1233

Merged
merged 1 commit into from Oct 2, 2019

Conversation

@pierre
Copy link
Member

commented Oct 1, 2019

In case a duplicate transaction external key was used, invoice would throw a NPE in the priorCall.

This fixes #1230.

In case a duplicate transaction external key was used, invoice would
throw a NPE in the priorCall.

This fixes #1230.

Signed-off-by: Pierre-Alexandre Meyer <pierre@mouraf.org>
@pierre pierre requested a review from sbrossie Oct 1, 2019
Preconditions.checkState(invoicePayment.getPaymentId().equals(existingAttempt.getPaymentId()),
"PaymentAttempt cannot change paymentId: attemptId=%s, newInvoicePaymentId=%s, existingPaymentId=%s", existingAttempt.getId(), invoicePayment.getPaymentId(), existingAttempt.getPaymentId());
updatedPaymentId = invoicePayment.getPaymentId();
}

This comment has been minimized.

Copy link
@sbrossie

sbrossie Oct 1, 2019

Member

Wouldn't it be simpler to do:

if (invoicePayment.getPaymentId() != null) {
   Preconditions.checkState(....);
    updatedPaymentId = invoicePayment.getPaymentId();
} else { 
  // default to paymentAttempt
  updatedPaymentId = existingAttempt.getPaymentId();
}

This comment has been minimized.

Copy link
@pierre

pierre Oct 1, 2019

Author Member

Not quite - Preconditions is only valid if existingAttempt.getPaymentId() != null.

But regardless, I wanted to call out the invalid branch explicitly (source of the bug).

@pierre pierre merged commit 67c0b58 into work-for-release-0.21.x Oct 2, 2019
5 checks passed
5 checks passed
ci/circleci: build Your tests passed on CircleCI!
Details
ci/circleci: integration-tests Your tests passed on CircleCI!
Details
ci/circleci: test-h2 Your tests passed on CircleCI!
Details
ci/circleci: test-mysql Your tests passed on CircleCI!
Details
ci/circleci: test-postgresql Your tests passed on CircleCI!
Details
@pierre pierre deleted the fix-for-1230 branch Oct 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.