Skip to content

Commit 27347f1

Browse files
committed
Fixed possible null error with SyncService
* Added synchronized to initUserState to make sure this class doesn't become partially initialized that could create null errors. - If SyncService.onCreate was started just before OneSignal init was called then the initUserState method might have been run on multiple threads. * Removed dead code - method updateIdentifier.
1 parent 36dd357 commit 27347f1

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

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

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -470,10 +470,13 @@ void doRetry() {
470470
static void initUserState(Context context) {
471471
appContext = context;
472472

473-
if (currentUserState != null) return;
473+
synchronized (syncLock) {
474+
if (currentUserState == null)
475+
currentUserState = new OneSignalStateSynchronizer().new UserState("CURRENT_STATE", true);
474476

475-
currentUserState = new OneSignalStateSynchronizer().new UserState("CURRENT_STATE", true);
476-
toSyncUserState = new OneSignalStateSynchronizer().new UserState("TOSYNC_STATE", true);
477+
if (toSyncUserState == null)
478+
toSyncUserState = new OneSignalStateSynchronizer().new UserState("TOSYNC_STATE", true);
479+
}
477480
}
478481

479482
static UserState getNewUserState() {
@@ -643,15 +646,6 @@ static void setSubscription(boolean enable) {
643646
}
644647
}
645648

646-
static void updateIdentifier(String identifier) {
647-
UserState userState = getUserStateForModification();
648-
try {
649-
userState.syncValues.put("identifier", identifier);
650-
} catch (JSONException e) {
651-
e.printStackTrace();
652-
}
653-
}
654-
655649
static void updateLocation(Double lat, Double log, Float accuracy, Integer type) {
656650
UserState userState = getUserStateForModification();
657651
try {

0 commit comments

Comments
 (0)