[
https://issues.apache.org/jira/browse/FINERACT-2552?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
devi pathak updated FINERACT-2552:
----------------------------------
Description:
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 issue is related to general null-safety improvements (e.g.,
FINERACT-2326), but focuses specifically on EMI calculation in
ProgressiveEMICalculator.
was:
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.
> 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
>
> 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 issue is related to general null-safety improvements (e.g.,
> FINERACT-2326), but focuses specifically on EMI calculation in
> ProgressiveEMICalculator.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)