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

fix: initialize deviceInfo before putting adKey there #56

Merged
merged 1 commit into from
Jun 5, 2023

Conversation

wzieba
Copy link
Collaborator

@wzieba wzieba commented Jun 3, 2023

This PR tries to address NPE crash that happens in GetAdKey#onPostExecute.

Unfortunately, I wasn't able to reproduce the issue, though I think that provided change will address the problem.

How NPE happens

In the constructor of ParselyTracker we, launch GetAdKey AsyncTask which, in its onPostExecute, adds adKey to deviceInfo Map.

But the deviceInfo Map is created after GetAdKey is executed. This makes it possible that deviceInfo won't be created before GetAdKey tries to use it - hence the NPE.

I wasn't able to reproduce the issue because GetAdKey#onPostExecute happens on the main thread, so we have race condition on the main thread, so it's impossible to modify flow via Thread#sleep.

How to test

As we don't have reproduction, please focus on the code - does the proposed change have some side effects? Did I miss something, will it break any other feature?

@wzieba wzieba marked this pull request as ready for review June 3, 2023 21:22
@@ -87,7 +87,6 @@ protected ParselyTracker(String siteId, int flushInterval, Context c) {
this.rootUrl = "https://p1.parsely.com/";
this.queueSizeLimit = 50;
this.storageSizeLimit = 100;
this.deviceInfo = this.collectDeviceInfo();
Copy link
Collaborator

Choose a reason for hiding this comment

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

The code looks good, @wzieba!
np: I understand that collectDeviceInfo is a map containing the device information. WDYT if instead of creating this map within the post execute of the GetKey task, we keep it in the constructor and move only the get key logic to the postExecute, so the GetAdKey is only responsible for obtaining/saving the key and not for collecting the device info.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point with keeping responsibilities seperately but collectDeviceInfo uses adKey property, which is assigned in GetAdKey, so that's why I moved creation of deviceInfo to GetAdKey.

Copy link
Collaborator

@atorresveiga atorresveiga left a comment

Choose a reason for hiding this comment

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

LGTM! :shipit:

@wzieba wzieba merged commit b3b5c99 into master Jun 5, 2023
@wzieba wzieba deleted the issue/55-fix_npe_in_get_add_key branch June 5, 2023 19:26
@wzieba wzieba linked an issue Jun 13, 2023 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NPE on GetAdKey#onPostExecute
2 participants