Skip to content

Commit 3b4fc98

Browse files
INTENG-12653 avoid potential NPE in session builder, add ERR_IMPROPER_REINITIALIZATION (#910)
1 parent 9e68c86 commit 3b4fc98

File tree

5 files changed

+16
-10
lines changed

5 files changed

+16
-10
lines changed

Branch-SDK/src/main/java/io/branch/referral/Branch.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.branch.referral;
22

33
import static io.branch.referral.BranchError.ERR_BRANCH_REQ_TIMED_OUT;
4+
import static io.branch.referral.BranchError.ERR_IMPROPER_REINITIALIZATION;
45
import static io.branch.referral.BranchPreinstall.getPreinstallSystemData;
56
import static io.branch.referral.BranchUtil.isTestModeEnabled;
67
import static io.branch.referral.PrefHelper.isValidBranchKey;
@@ -2879,6 +2880,7 @@ public void init() {
28792880
} else if (isReInitializing) {
28802881
// User called reInit but isRestartSessionRequested = false, meaning the new intent was
28812882
// not initiated by Branch and should not be considered a "new session", return early
2883+
if (callback != null) callback.onInitFinished(null, new BranchError("", ERR_IMPROPER_REINITIALIZATION));
28822884
return;
28832885
}
28842886

@@ -2888,12 +2890,12 @@ public void init() {
28882890
branch.isInstantDeepLinkPossible = false;
28892891
// invoke callback returning LatestReferringParams, which were parsed out inside readAndStripParam
28902892
// from either intent extra "branch_data", or as parameters attached to the referring app link
2891-
callback.onInitFinished(branch.getLatestReferringParams(), null);
2893+
if (callback != null) callback.onInitFinished(branch.getLatestReferringParams(), null);
28922894
// mark this session as IDL session
28932895
branch.addExtraInstrumentationData(Defines.Jsonkey.InstantDeepLinkSession.getKey(), "true");
28942896
// potentially routes the user to the Activity configured to consume this particular link
28952897
branch.checkForAutoDeepLinkConfiguration();
2896-
// we already invoked the callback for let's set it to null, make will still make the
2898+
// we already invoked the callback for let's set it to null, we will still make the
28972899
// init session request but for analytics purposes only
28982900
callback = null;
28992901
}

Branch-SDK/src/main/java/io/branch/referral/BranchError.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ public class BranchError {
4444
public static final int ERR_BRANCH_TRACKING_DISABLED = -117;
4545
/* Branch session is already initialized */
4646
public static final int ERR_BRANCH_ALREADY_INITIALIZED = -118;
47+
/* Reinitializing session without the flag, IntentKey.ForceNewBranchSession */
48+
public static final int ERR_IMPROPER_REINITIALIZATION = -119;
4749

4850
/**
4951
* <p>Returns the message explaining the error.</p>
@@ -143,6 +145,9 @@ private String initErrorCodeAndGetLocalisedMessage(int statusCode) {
143145
} else if (statusCode >= 400 || statusCode == ERR_BRANCH_INVALID_REQUEST) {
144146
errorCode_ = ERR_BRANCH_INVALID_REQUEST;
145147
errMsg = " The request was invalid.";
148+
} else if (statusCode == ERR_IMPROPER_REINITIALIZATION) {
149+
errorCode_ = ERR_IMPROPER_REINITIALIZATION;
150+
errMsg = "Intra-app linking (i.e. session reinitialization) requires an intent flag, \"branch_force_new_session\".";
146151
} else {
147152
errorCode_ = ERR_BRANCH_NO_CONNECTIVITY;
148153
errMsg = " Check network connectivity and that you properly initialized.";

Branch-SDK/src/main/java/io/branch/referral/BranchPostTask.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,8 @@
66
import org.json.JSONException;
77
import org.json.JSONObject;
88

9-
import java.util.ArrayList;
10-
import java.util.Iterator;
119
import java.util.concurrent.CountDownLatch;
1210

13-
import static io.branch.referral.BranchError.ERR_BRANCH_REQ_TIMED_OUT;
14-
1511
/**
1612
* Asynchronous task handling execution of server requests. Execute the network task on background
1713
* thread and request are executed in sequential manner. Handles the request execution in
@@ -67,9 +63,7 @@ protected void onPostExecute(ServerResponse serverResponse) {
6763
void onPostExecuteInner(ServerResponse serverResponse) {
6864
if (latch_ != null) {
6965
latch_.countDown();
70-
PrefHelper.Debug("latch_.countDown()");
7166
}
72-
PrefHelper.Debug("onPostExecute, serverResponse = " + serverResponse);
7367
if (serverResponse == null) {
7468
thisReq_.handleFailure(BranchError.ERR_BRANCH_INVALID_REQUEST, "Null response.");
7569
return;

ChangeLog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
# Branch Android SDK change log
2+
- v5.0.9
3+
* _*Master Release*_ - April 29, 2021
4+
* Avoid potential NPE
5+
* When reinitializing session without an expected intent flag, invoke callback with error rather than ignoring it.
6+
27
- v5.0.8
38
* _*Master Release*_ - April 29, 2021
49
* Fix bug can block UI thread

gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
VERSION_NAME=5.0.8
2-
VERSION_CODE=050008
1+
VERSION_NAME=5.0.9
2+
VERSION_CODE=050009
33
GROUP=io.branch.sdk.android
44

55
POM_DESCRIPTION=Use the Branch SDK (branch.io) to create and power the links that point back to your apps for all of these things and more. Branch makes it incredibly simple to create powerful deep links that can pass data across app install and open while handling all edge cases (using on desktop vs. mobile vs. already having the app installed, etc). Best of all, it is really simple to start using the links for your own app: only 2 lines of code to register the deep link router and one more line of code to create the links with custom data.

0 commit comments

Comments
 (0)