FINERACT-2689: Fix NPE in deposit withholding tax when net interest posted is zero#6126
Open
oluexpert99 wants to merge 1 commit into
Open
FINERACT-2689: Fix NPE in deposit withholding tax when net interest posted is zero#6126oluexpert99 wants to merge 1 commit into
oluexpert99 wants to merge 1 commit into
Conversation
…osted is zero - Closing (or posting interest on) a withholding-tax deposit account threw a 500 NullPointerException whenever the net interest posted on the account was zero: SavingsAccount.createWithHoldTransaction / updateWithHoldTransaction guard only on the tax group and then evaluate amount.compareTo(BigDecimal.ZERO), but amount can be null. SavingsAccountTransactionSummaryWrapper.calculateTotalInterestPosted returns total.getAmountDefaultedToNullIfZero() -- i.e. null -- when there are no net interest-posting transactions, and that null is passed straight into both helpers. - The common real-world trigger is premature-closing a short-term fixed deposit whose pre-closure penalty rate is greater than or equal to the chart rate: the effective interest is clamped to zero (FixedDepositAccount.getEffectiveInterestRateAsFraction), so postPreMaturityInterest posts no interest transaction, and the withholding-tax pass then runs with a null interest total. For a withholding-tax account the tax group is non-null, so the first clause passes and amount.compareTo throws; the whole command rolls back and the account cannot be closed. - Null-guard amount in both createWithHoldTransaction and updateWithHoldTransaction: a null (or non-positive) interest total means there is nothing to withhold tax on, so both no-op and return false. No behaviour change when interest is actually posted -- a non-null positive amount takes the same path as before. - Add a unit test (SavingsAccountWithHoldTaxNullAmountTest) that sets a non-null tax group so the guard is exercised rather than short-circuited, and asserts that a null or zero amount no longer throws and adds no withholding transaction. Signed-off-by: oluexpert99 <farooq@techservicehub.io>
44fe133 to
85f7906
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
NullPointerException whenever the net interest posted on the account was zero:
SavingsAccount.createWithHoldTransaction / updateWithHoldTransaction guard only on
the tax group and then evaluate amount.compareTo(BigDecimal.ZERO), but amount can be
null. SavingsAccountTransactionSummaryWrapper.calculateTotalInterestPosted returns
total.getAmountDefaultedToNullIfZero() -- i.e. null -- when there are no net
interest-posting transactions, and that null is passed straight into both helpers.
- The common real-world trigger is premature-closing a short-term fixed deposit whose
pre-closure penalty rate is greater than or equal to the chart rate: the effective
interest is clamped to zero (FixedDepositAccount.getEffectiveInterestRateAsFraction),
so postPreMaturityInterest posts no interest transaction, and the withholding-tax pass
then runs with a null interest total. For a withholding-tax account the tax group is
non-null, so the first clause passes and amount.compareTo throws; the whole command
rolls back and the account cannot be closed.
- Null-guard amount in both createWithHoldTransaction and updateWithHoldTransaction: a
null (or non-positive) interest total means there is nothing to withhold tax on, so
both no-op and return false. No behaviour change when interest is actually posted -- a
non-null positive amount takes the same path as before.
- Add a unit test (SavingsAccountWithHoldTaxNullAmountTest) that sets a non-null tax
group so the guard is exercised rather than short-circuited, and asserts that a null
or zero amount no longer throws and adds no withholding transaction.
Description
Describe the changes made and why they were made. (Ignore if these details are present on the associated Apache Fineract JIRA ticket.)
Checklist
Please make sure these boxes are checked before submitting your pull request - thanks!
Your assigned reviewer(s) will follow our guidelines for code reviews.