Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly check nullability when reading from JSON objects #1809

Merged
merged 3 commits into from
Oct 7, 2024

Conversation

jreij
Copy link
Collaborator

@jreij jreij commented Oct 7, 2024

Description

Replace JSONObject.has with !JSONObject.isNull when reading JSON values to ensure correct handling of null values.

Checklist

  • PR is labelled
  • Changes are tested manually
  • Related issues are linked

COAND-994

@jreij jreij added the Fix [PRs only] Indicates a bug fix label Oct 7, 2024
@jreij jreij requested a review from a team as a code owner October 7, 2024 07:42
@@ -20,22 +20,27 @@ private const val PARSING_ERROR = "PARSING_ERROR"

@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
fun JSONObject.getStringOrNull(key: String): String? {
return if (has(key)) getString(key) else null
return if (!isNull(key)) getString(key) else null
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't have tests for these functions. Can we add some tests so we know if something gets broken in the future?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We can indeed, the problem is that the bug we found cannot be reproduced in tests :/ I will add some anyway.

Copy link

github-actions bot commented Oct 7, 2024

✅ No public API changes

Copy link

sonarcloud bot commented Oct 7, 2024

@jreij jreij merged commit 95974fa into develop Oct 7, 2024
9 checks passed
@jreij jreij deleted the fix/json-serialization branch October 7, 2024 13:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Fix [PRs only] Indicates a bug fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

A value of fundingSource of Card payment is string "null" and it causes an exception in BE SDK
3 participants