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

Initialize deviceInfo in constructor of ParselyTracker #58

Merged
merged 2 commits into from
Sep 5, 2023

Conversation

wzieba
Copy link
Collaborator

@wzieba wzieba commented Sep 4, 2023

Closes: #57

Description

This PR addresses the issue reported in #57 by initializing deviceInfo synchronously in the constructor of the ParselyTracker, rather than waiting for GetAdKey async task to complete.

It brings back part of the behavior from before #56 (which introduced the discussed bug) but makes it more explicitly, that initial creation of deviceInfo passes null for adKey property.

Reproduction

  1. Checkout trunk
  2. Apply the PATCH
PATCH
Subject: [PATCH] refactor: move plugins configuration to pluginManagement
---
Index: parsely/src/main/java/com/parsely/parselyandroid/ParselyTracker.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/parsely/src/main/java/com/parsely/parselyandroid/ParselyTracker.java b/parsely/src/main/java/com/parsely/parselyandroid/ParselyTracker.java
--- a/parsely/src/main/java/com/parsely/parselyandroid/ParselyTracker.java	(revision 652ccbec41975239f3981289d94a40335f2495b2)
+++ b/parsely/src/main/java/com/parsely/parselyandroid/ParselyTracker.java	(date 1693839376735)
@@ -738,6 +738,11 @@
         protected String doInBackground(Void... params) {
             AdvertisingIdClient.Info idInfo = null;
             String advertId = null;
+            try {
+                Thread.sleep(10000);
+            } catch (InterruptedException e) {
+                throw new RuntimeException(e);
+            }
             try {
                 idInfo = AdvertisingIdClient.getAdvertisingIdInfo(mContext);
             } catch (GooglePlayServicesRepairableException | IOException | GooglePlayServicesNotAvailableException | IllegalArgumentException e) {
  1. Run the example app and within 10 seconds tap on "track url" button.

It makes codebase easier to understand and eliminates multiple sources
for `parsely_site_uuid`.
This change fixes crash in case of library user running
ParselyTracker#trackPageView (or any other tracking method) **before**
GetAdKey AsyncTask completes.
@wzieba wzieba requested a review from ParaskP7 September 4, 2023 15:02
@wzieba wzieba marked this pull request as ready for review September 4, 2023 15:02
@ParaskP7 ParaskP7 self-assigned this Sep 5, 2023
Copy link
Collaborator

@ParaskP7 ParaskP7 left a comment

Choose a reason for hiding this comment

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

👋 @wzieba !

I have reviewed and tested this PR as per the reproduction instructions, everything works as expected, I was able to crash the app without this.deviceInfo = collectDeviceInfo(null);, and able to verify that it is now not crashing when this line fix is included, good job, I think we can safely merge this now! 🌟 🌟 🌟

@@ -755,9 +755,7 @@ protected String doInBackground(Void... params) {

@Override
protected void onPostExecute(String advertId) {
adKey = advertId;
deviceInfo = collectDeviceInfo();
deviceInfo.put("parsely_site_uuid", adKey);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Question (❓): Just to confirm that, why was that deleted? My guess is because it is just being a duplicate of dInfo.put("parsely_site_uuid", uuid);, right?

FYI: Because this change was included as part of this 98c1dd6 refactor commit, which was mainly about removing the adKey field, it kind of made it harder for me to understand. Although you did add this on the description, I just want to be sure of it (🤷 + 😊): It makes codebase easier to understand and eliminates multiple sources for 'parsely_site_uuid'.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, this code was duplicating dInfo.put("parsely_site_uuid", uuid) from collectDeviceInfo.

@wzieba wzieba merged commit 8975468 into master Sep 5, 2023
1 check passed
@wzieba wzieba deleted the issue/57-fix-npe-for-null-deviceinfo branch September 5, 2023 10:58
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.

NullPointerException when accessing deviceInfo map in ParselyTracker.java
2 participants