Skip to content

Conversation

@airajena
Copy link
Contributor

@airajena airajena commented Jan 3, 2026

Description

Fixes NullPointerException that occurs in SavingsHelper.determineInterestPostingPeriods() when date parameters are null.

The NPE occurs when closing a Fixed Deposit account if the maturity date is null (e.g., when depositPeriodFrequencyType is INVALID).

Root Cause

The method determineInterestPostingPeriods() uses DateUtils.isAfter() which throws NPE when either startInterestCalculationLocalDate or interestPostingUpToDate is null.

Fix

Added null check at the start of the method to return an empty list early if either date parameter is null.

Testing

  • Fix compiles successfully
  • Verified the null check prevents the NPE scenario from the stack trace

Related Issue

Fixes FINERACT-1266

@adamsaghy
Copy link
Contributor

@airajena Please rebase this PR with latest develop branch.


final List<LocalDateInterval> postingPeriods = new ArrayList<>();

if (startInterestCalculationLocalDate == null || interestPostingUpToDate == null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please explain this new condition and why it is the correct behavior?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The null check prevents a NullPointerException that occurs when either startInterestCalculationLocalDate or interestPostingUpToDate is null.

DateUtils.isAfter() at line 64 throws NPE when comparing null dates, This happens when closing a Fixed Deposit account where depositPeriodFrequencyType is INVALID, causing the maturity date (and subsequently interestPostingUpToDate) to be null

If either date is null, there are no valid interest posting periods to determine

  • An empty list semantically means "no posting periods" - which is accurate when dates are undefined
  • This allows the calling code (e.g., account closure) to continue gracefully

I've also rebased the PR with the latest develop branch as requested.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In what situations can these values be null?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interestPostingUpToDate can be null when:
depositPeriodFrequencyType is INVALID: In FixedDepositAccount.calculateMaturityDate(), the switch statement handles DAYS, WEEKS, MONTHS, and YEARS, but when depositPeriodFrequencyType is INVALID, it falls through with an empty break, leaving maturityDate as null:

Database has null/invalid deposit_period_frequency_enum: SavingsPeriodFrequencyType.fromInt() returns INVALID when the input is null or an unrecognized value. The column deposit_period_frequency_enum is marked as nullable = true in DepositAccountTermAndPreClosure

Account reinvestment: DepositAccountTermAndPreClosure.copy() explicitly sets maturityDate = null when creating a copy for reinvestment.

startInterestCalculationLocalDate can be null when:
Account in early submission state: accountSubmittedOrActivationDate() could return null if both activationDate and submittedOnDate are null.

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

Kindly see my questions.

@airajena airajena force-pushed the FINERACT-1266/fix-npe-savings-helper branch from 3c22492 to 889857a Compare January 12, 2026 13:19
@adamsaghy adamsaghy merged commit 07d6749 into apache:develop Jan 15, 2026
34 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