-
Notifications
You must be signed in to change notification settings - Fork 207
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
Handle null values in MetaData.mergeMaps, preventing potential NPE #386
Conversation
MetaData tab values can be HashMaps, whose entries can be null. MetaData.mergeMaps seemed to assume that the Map was always a ConcurrentHashMap, whose values cannot be null, which could lead to a NPE when merging config.metaData and report.metaData for nullable values, such as activeScreen. Adding a null check and conditionally adding values fixes this behaviour.
if (baseValue != null | ||
&& baseValue instanceof Map | ||
&& overridesValue instanceof Map) { | ||
if (baseValue instanceof Map && overridesValue instanceof Map) { |
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.
baseValue != null
is redundant when also using instanceof
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.
This LGTM. I haven't run it yet but the automated test looks good.
At which line would it error before? The Bugsnag.addToTab("Custom", "foo", configMap)
or the notify()
call? (or both?)
This was originally discovered when setting the codeBundleId in React Native, which in turn sets metadata on the native layer: bugsnag/bugsnag-react-native#291 |
metaData.addToTab("foo", "bar", nestedMap); | ||
nestedMap.put("whoops", null); | ||
|
||
Map<String, Object> mergedMap = MetaData.merge(metaData, metaData).store; |
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.
Can we merge a different metadata? Its weird to read otherwise.
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.
I have updated the test to generate two different MetaData objects.
nestedMap.put("whoops", null); | ||
|
||
Map<String, Object> mergedMap = MetaData.merge(metaData, metaData).store; | ||
assertFalse(mergedMap.containsKey("whoops")); |
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.
I think this assertion is incorrect. Can you undo the changes to the sdk and check that this fails as you would expect? I would never expect the whoops key to be in this map from reading the test.
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.
Without the changes, this test fails due to a NPE within MetaData.mergeMaps
, which is expected. I have removed the assertFalse
statement as I can see it might be confusing. Were there any additional concerns around the assertions?
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.
Address my comments plz
…bjects when merging
b0a11da
@snmaynard I believe I have addressed the comments, are you happy with the updates? |
I pinged you with my concerns - we can discuss tomorrow! |
fix(gradle): replaced jcenter with mavenCentral
Goal
Prevent NPE crash when attempting to deliver error reports.
Design
MetaData
tab values can beHashMaps
, whose entries can be null.MetaData.mergeMaps
seemed to assume that theMap
was always aConcurrentHashMap
, whose entries cannot be null.On React Native this manifested as a NPE when merging
config.metaData
andreport.metaData
due toapp.activeScreen
being intermittently recorded as null. This can occur on any platform which uses bugsnag-android, however.Changeset
Added a null check when adding the base value to the merged map.
Tests
Wrote unit test + mazerunner scenario, and manually verified that valid reports are sent from a React Native example app using a local bugsnag-android artefact.
Review
For the submitter, initial self-review:
For the pull request reviewer(s), this changeset has been reviewed for: