You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@fineract.apache.org by "devi pathak (Jira)" <ji...@apache.org> on 2026/04/01 04:54:00 UTC
[jira] [Resolved] (FINERACT-2552) Potential NullPointerException in flat EMI calculation when no previous repayment period exists
[ https://issues.apache.org/jira/browse/FINERACT-2552?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
devi pathak resolved FINERACT-2552.
-----------------------------------
Resolution: Fixed
Fixed via PR #5685.
Handled a potential NullPointerException in flat EMI calculation when no previous repayment period exists, and added corresponding test coverage.
> Potential NullPointerException in flat EMI calculation when no previous repayment period exists
> -----------------------------------------------------------------------------------------------
>
> Key: FINERACT-2552
> URL: https://issues.apache.org/jira/browse/FINERACT-2552
> Project: Apache Fineract
> Issue Type: Bug
> Components: Loan
> Reporter: devi pathak
> Priority: Minor
> Labels: bugfix
>
> h3. Description
> While analyzing the flat interest EMI recalculation logic in {{{}ProgressiveEMICalculator{}}}, a potential NullPointerException was identified in {{{}calculateEMIOnActualModelWithFlatInterestMethod{}}}.
> h3. Problem
> In scenarios where recalculation starts from the first repayment period, {{firstRepaymentPeriod.getPrevious()}} can return empty. This results in {{alreadyRepaidPrincipals}} being assigned {{{}null{}}}, which is later used in a subtraction operation:
> {{.minus(alreadyRepaidPrincipals)}}
> This can lead to a runtime NullPointerException during EMI calculation.
> h3. Steps to Reproduce
> # Use flat interest method
> # Trigger recalculation starting from the first repayment period (e.g., during disbursement)
> # Observe potential failure due to null subtraction
> h3. Expected Behavior
> The calculation should safely handle cases where no previous repayment period exists.
> h3. Actual Behavior
> A null value is used in arithmetic operation, leading to potential runtime failure.
> h3. Solution
> Replace null fallback with a zero-value Money instance using the same currency context:
> {{.orElse(Money.zero(currency))}}
> h3. Impact
> * Improves robustness of EMI calculation
> * Prevents runtime exceptions in valid execution paths
> * No change in business logic
> h3. Additional Notes
> A unit test has been added to validate this scenario and ensure no regression.
>
--
This message was sent by Atlassian Jira
(v8.20.10#820010)