From d1052ab4e439816a0f5731d87fa0a9e282071c45 Mon Sep 17 00:00:00 2001 From: Wilfred Kigenyi Date: Mon, 2 Dec 2024 00:38:11 +0300 Subject: [PATCH] Confirm existance of elements before accessing them --- .../portfolio/savings/domain/SavingsAccount.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/fineract-savings/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccount.java b/fineract-savings/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccount.java index bfd94a1ead7..8288e7177ed 100644 --- a/fineract-savings/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccount.java +++ b/fineract-savings/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccount.java @@ -1594,12 +1594,19 @@ public void validateAccountBalanceDoesNotBecomeNegative(final String transaction public void validateAccountBalanceDoesNotViolateOverdraft(final List savingsAccountTransaction, final BigDecimal amountPaid) { if (savingsAccountTransaction != null) { - SavingsAccountTransaction savingsAccountTransactionFirst = savingsAccountTransaction.get(0); - if (!this.allowOverdraft) { - if (savingsAccountTransactionFirst.getRunningBalance(this.currency).minus(amountPaid).isLessThanZero()) { + if(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", getAccountBalance(), null, amountPaid); } } + } }