-
Notifications
You must be signed in to change notification settings - Fork 17
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
Failsafe to ensure obj is not nil when creating dict literal #218
Merged
akornich
merged 1 commit into
rollbar:master
from
okalentiev:bugfix/215-json-serialization-crash
Aug 4, 2022
Merged
Failsafe to ensure obj is not nil when creating dict literal #218
akornich
merged 1 commit into
rollbar:master
from
okalentiev:bugfix/215-json-serialization-crash
Aug 4, 2022
Conversation
This file contains 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
akornich
added
bug
Something isn't working
RollbarNotifier
RollbarNotifier mosule specific
labels
Aug 4, 2022
akornich
added
RollbarCommon
RollbarCommon module specific
and removed
RollbarNotifier
RollbarNotifier mosule specific
labels
Aug 4, 2022
akornich
approved these changes
Aug 4, 2022
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is a very useful last-chance defense. Thank you, @okalentiev !
This was referenced Aug 4, 2022
Closed
We're currently experiencing crash due the same problem.
Can someone please have a look. 46 crashes / 18 users
|
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.
Description of the change
This PR adds a defensive failsafe to ensure that object is not nil while serializing it. In case of nil, Foundation throws the following exception:
-[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[0]
.My first assumption was that this might happen due to implicit coercing of Swift's optional values to
the Any
type. For this, I have added a test case with a nil optional string. However, this worked as expected, resulting in a JSON with anull
values added and no exception thrown.To reproduce the error, I hardcoded
obj
to nil in the following way:Then I could get an exception. Additionally I also tried to play with different objects and dictionaries containing nil values, but could not trigger exceptions.
This change might not be conceptually correct since the nil value's root cause is unclear. However, a defensive fix is a small price for not crashing the app.
Type of change
Related issues
Checklists
Development
Code review