Confirm existance of elements before accessing them

This commit is contained in:
Wilfred Kigenyi
2025-03-14 12:59:35 +00:00
committed by Adam Saghy
parent 898a18c873
commit 2ac1445dba
2 changed files with 320 additions and 1 deletions
@@ -1593,13 +1593,18 @@ public class SavingsAccount extends AbstractAuditableWithUTCDateTimeCustom<Long>
public void validateAccountBalanceDoesNotViolateOverdraft(final List<SavingsAccountTransaction> savingsAccountTransaction,
final BigDecimal amountPaid) {
if (savingsAccountTransaction != null) {
if (savingsAccountTransaction != null && savingsAccountTransaction.size() > 0) {
SavingsAccountTransaction savingsAccountTransactionFirst = savingsAccountTransaction.get(0);
if (!this.allowOverdraft) {
if (savingsAccountTransactionFirst.getRunningBalance(this.currency).minus(amountPaid).isLessThanZero()) {
throw new InsufficientAccountBalanceException("transactionAmount", getAccountBalance(), null, amountPaid);
}
}
} else {
if (!this.allowOverdraft) {
throw new InsufficientAccountBalanceException("transactionAmount", BigDecimal.ZERO, null, amountPaid);
}
}
}