Skip to content

Commit 16fa897

Browse files
committed
Synchronize State
• Fixes a crash where the generateJsonDiff() method of the currentUserState property in UserStateSynchronizer is called before the currentUserState is initialized, by adding a synchronization step to the initUserState() method • Adds a check to make sure the user state is initialized before internalSyncUserState() attempts to access it.
1 parent 3c13a2b commit 16fa897

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,10 @@ protected synchronized UserState getToSyncUserState() {
119119
}
120120

121121
void initUserState() {
122-
if (currentUserState == null)
123-
currentUserState = newUserState("CURRENT_STATE", true);
122+
synchronized (syncLock) {
123+
if (currentUserState == null)
124+
currentUserState = newUserState("CURRENT_STATE", true);
125+
}
124126

125127
getToSyncUserState();
126128
}
@@ -167,6 +169,9 @@ private void internalSyncUserState(boolean fromSyncService) {
167169
return;
168170
}
169171

172+
if (currentUserState == null)
173+
initUserState();
174+
170175
final boolean isSessionCall = isSessionCall();
171176
JSONObject jsonBody, dependDiff;
172177
synchronized (syncLock) {

0 commit comments

Comments
 (0)