[
https://issues.apache.org/jira/browse/FINERACT-2950?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18127413#comment-18127413
]
Senesh Perera commented on FINERACT-2950:
-----------------------------------------
Submitted PR: https://github.com/apache/fineract/pull/6651
> LoanDisbursementDetails.equals() uses scale-sensitive BigDecimal.equals()
> causing unnecessary loan schedule recalculation and potential NPE
> -------------------------------------------------------------------------------------------------------------------------------------------
>
> Key: FINERACT-2950
> URL: https://issues.apache.org/jira/browse/FINERACT-2950
> Project: Apache Fineract
> Issue Type: Bug
> Components: Loan
> Reporter: Senesh Perera
> Priority: Minor
> Labels: bug, loan
>
> In LoanDisbursementDetails, equals() compares principal using
> BigDecimal.equals():
> return loanDisbursementDetails.principal.equals(this.principal)
> &&
> DateUtils.isEqual(loanDisbursementDetails.expectedDisbursementDate,
> this.expectedDisbursementDate);
> Issues:
> 1. Scale mismatch: Stored principals use DECIMAL(19,6) (e.g. 1000.000000),
> while request principals parsed in LoanDisbursementService preserve the JSON
> scale (e.g. 1000). Because BigDecimal.equals() is scale-sensitive, unchanged
> disbursement tranches are treated as modified in
> LoanDisbursementService.updateDisbursementDetails(), triggering unnecessary
> schedule recalculations (RECALCULATE_LOAN_SCHEDULE = true).
> 2. NullPointerException: If principal is null on the incoming object,
> principal.equals(...) throws a NullPointerException.
> 3. hashCode() mismatch: Objects.hash(expectedDisbursementDate, principal) is
> also scale-sensitive, breaking the equals/hashCode contract when comparing
> across scales.
> Expected Behavior:
> - Compare principal values null-safely using compareTo() == 0 (or
> MathUtil.isEqualTo).
> - Normalize principal in hashCode() using stripTrailingZeros() so equal
> instances return the same hash code.
> - Add unit tests in LoanDisbursementDetailsTest covering scale differences
> and null values.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)