ImalkaPerera opened a new pull request, #6651:
URL: https://github.com/apache/fineract/pull/6651

   ## Description
   
   JIRA: https://issues.apache.org/jira/browse/FINERACT-2950
   
   `LoanDisbursementDetails.equals()` and `hashCode()` have three defects:
   
   1. **Scale-sensitive comparison.** `equals()` used `BigDecimal.equals` on 
`principal`, which also compares scale. `m_loan_disbursement_detail.principal` 
is `DECIMAL(19,6)`, so a stored `1000.000000` is not equal to a request value 
`1000`, even though the amounts and dates are identical. In 
`LoanDisbursementService` (tranche edit) this makes an unchanged tranche look 
modified and can trigger an unnecessary schedule recalculation.
   2. **NPE.** `this.principal.equals(...)` / `compareTo` paths throw when a 
principal is `null`.
   3. **Inconsistent `hashCode()`.** `hashCode()` must agree with `equals()`; 
once equality ignores scale, hashing the raw `BigDecimal` would break the 
contract.
   
   ### Fix
   
   - `equals()`: null-safe, scale-insensitive principal comparison 
(`compareTo() == 0`); `null` is only equal to `null` (never to zero). 
Expected-disbursement-date comparison via `DateUtils.isEqual` is unchanged.
   - `hashCode()`: hashes a normalised principal (`stripTrailingZeros()`, with 
zero special-cased because `0` vs `0.000000` strip differently on some JDKs), 
keeping it consistent with `equals()`.
   
   ### Tests
   
   New `LoanDisbursementDetailsTest` (JUnit 5, 10 tests):
   - equality and hashCode for `1000` vs `1000.000000`, `0` vs `0.000000`, 
`1000.50` vs `1000.500000`
   - no NPE when this / other / both principals are `null`; `null` is not equal 
to zero
   - different principals and different expected dates are not equal
   
   Three of these fail on unmodified `develop` and pass with the fix.
   
   `./gradlew :fineract-loan:spotlessApply :fineract-loan:check` passes locally 
(checkstyle, spotless, tests).
   
   Note: the effect on tranche-edit recalculation is derived from reading the 
code path (`LoanDisbursementService`), not from an end-to-end HTTP run.
   
   ## Checklist
   
   - [x] Write the commit message as per [our 
guidelines](https://github.com/apache/fineract/blob/develop/CONTRIBUTING.md#pull-requests)
   - [x] 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.
   - [x] Create/update [unit or integration 
tests](https://fineract.apache.org/docs/current/#_testing) for verifying the 
changes made.
   - [x] Follow our [coding 
conventions](https://cwiki.apache.org/confluence/display/FINERACT/Coding+Conventions).
   - [x] 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 (N/A, no API change)
   - [x] [This PR must not be a "code 
dump"](https://cwiki.apache.org/confluence/display/FINERACT/Pull+Request+Size+Limit).
 Large changes can be made in a branch, with assistance. Ask for help on the 
[developer mailing list](https://fineract.apache.org/#contribute).
   - [x] If merging this PR resolves a JIRA issue, I will mark that issue as 
resolved and set "Fix Version/s" appropriately.
   - [x] I followed the [AI 
Policy](https://github.com/apache/fineract/blob/develop/CONTRIBUTING.md#ai-policy).
   
   Your assigned reviewer(s) will follow our [guidelines for code 
reviews](https://cwiki.apache.org/confluence/display/FINERACT/Code+Review+Guide).


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to