Skip to content

Conversation

@budaidev
Copy link
Contributor

Description

Describe the changes made and why they were made. (Ignore if these details are present on the associated Apache Fineract JIRA ticket.)

Checklist

Please make sure these boxes are checked before submitting your pull request - thanks!

  • Write the commit message as per our guidelines
  • Acknowledge that we will not review PRs that are not passing the build ("green") - it is your responsibility to get a proposed PR to pass the build, not primarily the project's maintainers.
  • Create/update unit or integration tests for verifying the changes made.
  • Follow our coding conventions.
  • Add required Swagger annotation and update API documentation at fineract-provider/src/main/resources/static/legacy-docs/apiLive.htm with details of any API changes
  • This PR must not be a "code dump". Large changes can be made in a branch, with assistance. Ask for help on the developer mailing list.

Your assigned reviewer(s) will follow our guidelines for code reviews.

@adamsaghy adamsaghy marked this pull request as ready for review January 12, 2026 09:43
Comment on lines 629 to 641
Money totalOverDueInterest = Money.zero(currency);

if (previousInstallments.isEmpty()) {
loanTransaction.resetDerivedComponents();
loanTransaction.updateComponentsAndTotal(totalOverDuePrincipal, totalOverDueInterest, Money.zero(currency),
Money.zero(currency));
if (loanTransaction.isNotReversed()) {
loanTransaction.reverse();
loanTransaction.manuallyAdjustedOrReversed();
}
return;
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please help me understand what this logic is for?

Also seems reused multiple times, we might wanna extract this into a method.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic handles an edge case where re-amortization is requested on disbursement day. At this point, previousInstallments (installments with due date ≤ transaction date) is empty because all installments are scheduled in the future.

Without this guard, calling previousInstallments.getLast() throws NoSuchElementException causing a 500 error.

The fix gracefully handles this by:

  1. Setting transaction amounts to zero
  2. Reversing the transaction (since there's nothing to re-amortize)
  3. Returning early

This is consistent with the existing logic that reverses the transaction when both principal and interest are zero

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@budaidev I see. Thanks, then just extract the common logic and reuse it! ;)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

However, there is 1 thought... if there is no any reamortizable amount, maybe we should just throw a domain rule exception and explain, Reamortization cannot be executed, hence no overdue amount.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I modified it so we should throw an error in these cases

Copy link
Contributor

@adamsaghy adamsaghy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kindly see my concerns!

@budaidev budaidev force-pushed the FINERACT-2354/fix-reammortization-bug branch 2 times, most recently from d70c702 to a8efa41 Compare January 13, 2026 11:16
@budaidev budaidev requested a review from adamsaghy January 13, 2026 11:55
@budaidev budaidev force-pushed the FINERACT-2354/fix-reammortization-bug branch from a8efa41 to 1767b72 Compare January 13, 2026 19:04
@budaidev
Copy link
Contributor Author

@adamsaghy I have made some test changes according the validation we discussed here

@adamsaghy adamsaghy merged commit 442290e into apache:develop Jan 15, 2026
35 checks passed
@adamsaghy adamsaghy deleted the FINERACT-2354/fix-reammortization-bug branch January 15, 2026 09:17
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.

2 participants