[
https://issues.apache.org/jira/browse/FINERACT-2694?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Adam Saghy updated FINERACT-2694:
---------------------------------
Fix Version/s: 1.16.0
> POST /smscampaigns, /emailcampaigns and /standinginstructions return 500
> NullPointerException instead of validation error when
> triggerType/campaignType/transferType is omitted
> -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
> Key: FINERACT-2694
> URL: https://issues.apache.org/jira/browse/FINERACT-2694
> Project: Apache Fineract
> Issue Type: Bug
> Components: Savings
> Affects Versions: 1.15.0
> Reporter: Abhishek Chaudhary
> Assignee: Abhishek Chaudhary
> Priority: Major
> Labels: validation
> Fix For: 1.16.0
>
>
> *Affected endpoints:*
> * {{POST /smscampaigns}} and {{PUT /smscampaigns/\{id\}}} — omitting
> {{triggerType}}
> * {{POST /emailcampaigns}} and {{PUT /emailcampaigns/\{id\}}} — omitting
> {{campaignType}}
> * {{POST /standinginstructions}} — omitting {{transferType}}
> *Steps to reproduce* (any of the three):
> # {{POST /fineract-provider/api/v1/smscampaigns}} with a body that omits
> {{triggerType}}:
> {code:json}
> {"campaignName": "test"}
> {code}
> # {{POST /fineract-provider/api/v1/emailcampaigns}} with a body that omits
> {{campaignType}}
> # {{POST /fineract-provider/api/v1/standinginstructions}} with a body that
> omits {{transferType}}
> *Observed behaviour:*
> {color:red}HTTP 500 Internal Server Error{color}
> {noformat}
> java.lang.NullPointerException: Cannot invoke "java.lang.Long.intValue()"
> because "triggerType" is null
> {noformat}
> (for standing instructions the NPE comes from the {{switch}} on a null
> {{Integer}} in {{AccountTransferType.fromInt(null)}})
> *Expected behaviour:*
> bq. HTTP 400 with a {{PlatformApiDataValidationException}} payload reporting
> that the parameter is mandatory, e.g.
> {{validation.msg.sms.triggerType.cannot.be.blank}}
> *Root cause:*
> The validators queue a {{notNull()}} validation error via
> {{DataValidatorBuilder}} but _dereference the extracted value before_
> {{throwExceptionIfValidationWarningsExist()}} runs, so the queued error is
> never returned:
> * {{SmsCampaignValidator.validateCreate}} / {{validateForUpdate}} —
> {{triggerType.intValue()}}
> * {{EmailCampaignValidator.validateCreate}} / {{validateForUpdate}} —
> {{campaignType.intValue()}}
> * {{StandingInstructionDataValidator.validateForCreate}} —
> {{AccountTransferType.fromInt(transferType)}}
> In {{StandingInstructionDataValidator}} every _neighbouring_ parameter in the
> same method ({{recurrenceType}}, {{recurrenceFrequency}}, {{toAccountType}},
> {{standingInstructionType}}, {{fromAccountType}}) *is* null-guarded — this
> one was missed.
> Same defect class as FINERACT-2689 (fixed in PR
> [#6126|https://github.com/apache/fineract/pull/6126]) and FINERACT-2665 (PR
> [#6059|https://github.com/apache/fineract/pull/6059]).
> *Proposed fix:*
> Null-guard the seven dereference sites so the already-queued validation
> errors surface. No behaviour change for valid requests. Regression tests
> included ({{SmsCampaignValidatorTest}}, {{EmailCampaignValidatorTest}},
> {{StandingInstructionDataValidatorTest}} — the NPE tests fail without the
> fix).
> {code} blocks and {noformat} render as code/preformatted panels in ASF Jira;
> the `\{id\}` escapes stop Jira from interpreting `{id}` as a macro; `#` lines
> render as a numbered list, `*` lines as bullets.
> One caution: don't put the markup in the *summary* field — Jira titles render
> markup literally.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)