Skip to content

FINERACT-2421: Add equals() and hashCode() to LoanTransaction#5855

Merged
adamsaghy merged 1 commit into
apache:developfrom
Harshdhall01:fix/loan-transaction-equals-hashcode
May 22, 2026
Merged

FINERACT-2421: Add equals() and hashCode() to LoanTransaction#5855
adamsaghy merged 1 commit into
apache:developfrom
Harshdhall01:fix/loan-transaction-equals-hashcode

Conversation

@Harshdhall01
Copy link
Copy Markdown
Contributor

@Harshdhall01 Harshdhall01 commented May 15, 2026

Description

LoanTransaction was missing equals() and hashCode() implementations,
flagged by a long-standing TODO comment in the code:

// TODO missing hashCode(), equals(Object obj), but probably OK as long as
// this is never stored in a Collection.

The parent class AbstractPersistableCustom intentionally omits these methods
(documented in its own Javadoc). Added id-based implementations consistent with
the pattern already used in LoanDisbursementDetails, ensuring correct behavior
if LoanTransaction is ever used in hash-based collections.

Changes

  • Removed stale TODO comment
  • Added equals() based on entity id with null-safety for unsaved entities
  • Added hashCode() based on entity id
  • Added missing java.util.Objects import

I am exploring this codebase as part of my DMP 2026 (C4GT) application for the
"Dynamic Pricing of Micro-loans Using Reinforcement Learning" project under
openMF/Mifos. The loan module is directly relevant as it contains the core
transaction logic that my RL environment will model for dynamic pricing decisions.

Checklist

  • Write the commit message as per our guidelines
  • Acknowledge that we will not review PRs that are not passing the build
  • Create/update unit or integration tests for verifying the changes made
  • Follow our coding conventions
  • Add required Swagger annotation and update API documentation
  • This PR must not be a "code dump"

@Harshdhall01 Harshdhall01 force-pushed the fix/loan-transaction-equals-hashcode branch from 638fc79 to 78ae5e4 Compare May 18, 2026 14:31
@adamsaghy
Copy link
Copy Markdown
Contributor

@Harshdhall01 Please use FINERACT-2421 for this.

@Harshdhall01 Harshdhall01 force-pushed the fix/loan-transaction-equals-hashcode branch from 78ae5e4 to 771c404 Compare May 19, 2026 11:46
@Harshdhall01 Harshdhall01 changed the title FINERACT-xxxx: Add equals() and hashCode() to LoanTransaction FINERACT-2421: Add equals() and hashCode() to LoanTransaction May 19, 2026
@Harshdhall01
Copy link
Copy Markdown
Contributor Author

Thank you @adamsaghy! Sir Updated the commit and PR title to FINERACT-2421.

@Harshdhall01
Copy link
Copy Markdown
Contributor Author

The build failure in fineract-progressive-loan is a pre-existing
ReferenceEquality issue in AdvancedPaymentScheduleTransactionProcessor.java
(lines 1267, 1358) that uses == instead of .equals() for LoanTransaction
comparison. This is unrelated to my change — the errorprone check flags
reference equality regardless of whether equals() is implemented.

@adamsaghy
Copy link
Copy Markdown
Contributor

The build failure in fineract-progressive-loan is a pre-existing ReferenceEquality issue in AdvancedPaymentScheduleTransactionProcessor.java (lines 1267, 1358) that uses == instead of .equals() for LoanTransaction comparison. This is unrelated to my change — the errorprone check flags reference equality regardless of whether equals() is implemented.

It fails because now there is a value equality method available and it tries to enforce it now :)

You should fix these issues by modifying to use from now on the equals method

@Harshdhall01 Harshdhall01 force-pushed the fix/loan-transaction-equals-hashcode branch from 771c404 to 6e701e9 Compare May 20, 2026 16:49
@Harshdhall01
Copy link
Copy Markdown
Contributor Author

Thank you for the explanation @adamsaghy! Sir Fixed both lines in AdvancedPaymentScheduleTransactionProcessor.java to use Objects.equals() instead of ==. Force pushed the updated commit.

@adamsaghy
Copy link
Copy Markdown
Contributor

@Harshdhall01 Please review and resolve the build issues

@Harshdhall01 Harshdhall01 force-pushed the fix/loan-transaction-equals-hashcode branch from 6e701e9 to 9d3f05e Compare May 21, 2026 16:52
@Harshdhall01
Copy link
Copy Markdown
Contributor Author

@adamsaghy Sir Fixed the spotless formatting violations — removed extra blank lines in LoanTransaction.java. Force pushed the updated commit.

@Harshdhall01
Copy link
Copy Markdown
Contributor Author

@adamsaghy Sir All build issues resolved! spotless, checkstyle, and all integration tests are passing. The only remaining failure is api-compatibility-check which appears to be a pre-existing issue on develop unrelated to this change.
Ready for review!

Copy link
Copy Markdown
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.

LGTM

@adamsaghy adamsaghy merged commit 18097f3 into apache:develop May 22, 2026
102 of 107 checks passed
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