Skip to content

FINERACT-2790: Fix NoSuchElementException on Merchant Issued Refund for re-aged progressive loans - #6344

Open
AshharAhmadKhan wants to merge 1 commit into
apache:developfrom
AshharAhmadKhan:FINERACT-2790-merchant-refund-additional-installment
Open

FINERACT-2790: Fix NoSuchElementException on Merchant Issued Refund for re-aged progressive loans#6344
AshharAhmadKhan wants to merge 1 commit into
apache:developfrom
AshharAhmadKhan:FINERACT-2790-merchant-refund-additional-installment

Conversation

@AshharAhmadKhan

Copy link
Copy Markdown
Contributor

JIRA
https://issues.apache.org/jira/browse/FINERACT-2790

Problem
A Merchant Issued Refund on a progressive loan schedule crashes with an unwrapped NoSuchElementException when the loan has an "additional" installment in its persisted schedule (inserted by a prior re-age), the product has down payments enabled, and the payment allocation rule is MERCHANT_ISSUED_REFUND with futureInstallmentAllocationRule = LAST_INSTALLMENT.

The crash happens because AdvancedPaymentScheduleTransactionProcessor.updateRepaymentPeriodBalances() did not exclude isAdditional() installments before calling ProgressiveEMICalculator.getDueAmounts(). Additional installments are filtered out of the EMI model's repaymentPeriods at build time, so a lookup using an additional installment's dates has nothing to find.

Grepped all call sites of isDownPayment() and isAdditional() in fineract-progressive-loan/src/main/java and found 17 places where both are already excluded together. This is an established convention in the module: down payment and additional installments are both "special installments" excluded from EMI-model-based lookups. The LAST_INSTALLMENT selection logic already excludes isAdditional() from candidacy, so this was a downstream consumer that hadn't caught up to that rule, not a missing design decision.

Fix
Excludes isAdditional() installments in updateRepaymentPeriodBalances() the same way isDownPayment() installments are already excluded.

Verification
Added test coverage to the existing AdvancedPaymentScheduleTransactionProcessorTest and ProgressiveEMICalculatorTest suites (no standalone ticket-numbered test classes, per the module's convention):

  • updateRepaymentPeriodBalancesSkipsAdditionalInstallmentAndAppliesPaymentDirectly asserts getDueAmounts() is never called for an additional installment and that the payment is applied directly to its own persisted principal balance instead.
  • getDueAmountsThrowsNoSuchElementExceptionForAdditionalInstallment reproduces the original crash mechanism directly against ProgressiveEMICalculator.

…or re-aged progressive loans

AdvancedPaymentScheduleTransactionProcessor.updateRepaymentPeriodBalances() did not exclude
isAdditional() installments before calling ProgressiveEMICalculator.getDueAmounts(), which
throws NoSuchElementException because additional installments (inserted by a prior re-age)
are filtered out of the EMI model's repaymentPeriods at build time.

This surfaced when a Merchant Issued Refund with MERCHANT_ISSUED_REFUND payment allocation
and futureInstallmentAllocationRule = LAST_INSTALLMENT selected an additional installment
as the in-advance target.

The fix excludes isAdditional() installments the same way isDownPayment() installments are
already excluded, consistent with the existing convention used elsewhere in this module
(both are treated as 'special installments' excluded from EMI-model-based lookups).
@AshharAhmadKhan

Copy link
Copy Markdown
Contributor Author

Hey @adamsaghy , failure unrelated to my code. Please retrigger whenever possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant