Skip to content

Commit 0c4e905

Browse files
committed
Fix NPE: use a getter for the current UserState
* The currentUserState could be null from a user's report * Replace currentUserState with getCurrentUserState() to avoid an NPE * Replaced more instances of currentUserState with getCurrentUserState() than just the cases reported by the user. Which are all the places in UserStateSynchronizer that access currentUserState and it could possibly be null.
1 parent 5f40a60 commit 0c4e905

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

OneSignalSDK/onesignal/src/main/java/com/onesignal/UserStateSynchronizer.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ private void internalSyncUserState(boolean fromSyncService) {
266266
final boolean isSessionCall = !fromSyncService && isSessionCall();
267267
JSONObject jsonBody, dependDiff;
268268
synchronized (LOCK) {
269-
jsonBody = currentUserState.generateJsonDiff(getToSyncUserState(), isSessionCall);
269+
jsonBody = getCurrentUserState().generateJsonDiff(getToSyncUserState(), isSessionCall);
270270
UserState toSyncState = getToSyncUserState();
271271
dependDiff = currentUserState.generateJsonDiffFromDependValues(toSyncState, null);;
272272
OneSignal.onesignalLog(OneSignal.LOG_LEVEL.DEBUG, "UserStateSynchronizer internalSyncUserState from session call: "+ isSessionCall + " jsonBody: " + jsonBody);
@@ -290,7 +290,7 @@ private void doEmailLogout(String userId) {
290290
String urlStr = "players/" + userId + "/email_logout";
291291
JSONObject jsonBody = new JSONObject();
292292
try {
293-
ImmutableJSONObject dependValues = currentUserState.getDependValues();
293+
ImmutableJSONObject dependValues = getCurrentUserState().getDependValues();
294294
if (dependValues.has(EMAIL_AUTH_HASH_KEY))
295295
jsonBody.put(EMAIL_AUTH_HASH_KEY, dependValues.optString(EMAIL_AUTH_HASH_KEY));
296296

@@ -333,7 +333,7 @@ private void logoutEmailSyncSuccess() {
333333
toSyncUserState.removeFromSyncValues(EMAIL_KEY);
334334
toSyncUserState.persistState();
335335

336-
currentUserState.removeFromDependValues(EMAIL_AUTH_HASH_KEY);
336+
getCurrentUserState().removeFromDependValues(EMAIL_AUTH_HASH_KEY);
337337
currentUserState.removeFromSyncValues(PARENT_PLAYER_ID);
338338
String emailLoggedOut = currentUserState.getSyncValues().optString(EMAIL_KEY);
339339
currentUserState.removeFromSyncValues(EMAIL_KEY);
@@ -379,7 +379,7 @@ void onFailure(int statusCode, String response, Throwable throwable) {
379379
@Override
380380
void onSuccess(String response) {
381381
synchronized (LOCK) {
382-
currentUserState.persistStateAfterSync(dependDiff, jsonBody);
382+
getCurrentUserState().persistStateAfterSync(dependDiff, jsonBody);
383383
onSuccessfulSync(jsonBody);
384384
}
385385

@@ -422,7 +422,7 @@ void onFailure(int statusCode, String response, Throwable throwable) {
422422
void onSuccess(String response) {
423423
synchronized (LOCK) {
424424
waitingForSessionResponse = false;
425-
currentUserState.persistStateAfterSync(dependDiff, jsonBody);
425+
getCurrentUserState().persistStateAfterSync(dependDiff, jsonBody);
426426

427427
try {
428428
OneSignal.onesignalLog(OneSignal.LOG_LEVEL.DEBUG, "doCreateOrNewSession:response: " + response);
@@ -468,7 +468,7 @@ private void handleNetworkFailure(int statusCode) {
468468
}
469469

470470
private void fireNetworkFailureEvents() {
471-
final JSONObject jsonBody = currentUserState.generateJsonDiff(toSyncUserState, false);
471+
final JSONObject jsonBody = getCurrentUserState().generateJsonDiff(toSyncUserState, false);
472472
if (jsonBody != null)
473473
fireEventsForUpdateFailure(jsonBody);
474474

@@ -570,7 +570,7 @@ private void handlePlayerDeletedFromServer() {
570570
}
571571

572572
void resetCurrentState() {
573-
currentUserState.setSyncValues(new JSONObject());
573+
getCurrentUserState().setSyncValues(new JSONObject());
574574
currentUserState.persistState();
575575
}
576576

0 commit comments

Comments
 (0)