Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -289,14 +289,18 @@ private fun buildPhpBeneficiary(node: JsonNode?): PhpExternalAccountCreateInfo.B

private fun buildEurBeneficiary(node: JsonNode?): EurExternalAccountCreateInfo.Beneficiary {
val f = parseBeneficiaryFields(node)
val countryOfResidence = node?.optText("countryOfResidence")
?: f.nationality
?: throw IllegalArgumentException("EUR beneficiary requires countryOfResidence")
Comment on lines +292 to +294

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Silent fallback from nationality to countryOfResidence

parseBeneficiaryFields (line 196) sets f.nationality to node.optText("countryOfResidence") ?: node.optText("nationality"). The fallback chain here means that when countryOfResidence is absent but nationality is present (e.g., "nationality": "DE"), the nationality value is silently used as the country of residence. This bypasses the IllegalArgumentException guard entirely despite the validation message. Additionally, node?.optText("countryOfResidence") in the first line is redundant — it is always equal to the countryOfResidence portion of f.nationality, so the first ?: never changes the outcome.

Prompt To Fix With AI
This is a comment left during a code review.
Path: samples/kotlin/src/main/kotlin/com/grid/sample/routes/ExternalAccounts.kt
Line: 292-294

Comment:
**Silent fallback from `nationality` to `countryOfResidence`**

`parseBeneficiaryFields` (line 196) sets `f.nationality` to `node.optText("countryOfResidence") ?: node.optText("nationality")`. The fallback chain here means that when `countryOfResidence` is absent but `nationality` is present (e.g., `"nationality": "DE"`), the nationality value is silently used as the country of residence. This bypasses the `IllegalArgumentException` guard entirely despite the validation message. Additionally, `node?.optText("countryOfResidence")` in the first line is redundant — it is always equal to the `countryOfResidence` portion of `f.nationality`, so the first `?:` never changes the outcome.

How can I resolve this? If you propose a fix, please make it concise.

return EurExternalAccountCreateInfo.Beneficiary.ofIndividual(
EurBeneficiary.builder()
.beneficiaryType(EurBeneficiary.BeneficiaryType.INDIVIDUAL)
.fullName(f.fullName)
.address(f.address ?: throw IllegalArgumentException("EUR beneficiary requires an address"))
.countryOfResidence(countryOfResidence)
.apply {
f.nationality?.let { nationality(it) }
f.birthDate?.let { birthDate(it) }
f.address?.let { address(it) }
}
.build()
)
Expand Down
Loading