fix Spot Bugs warning

Possible null pointer dereference in com.nextcloud.talk.utils.PushUtils.updatePushStateForUser(Map, User) due to return value of called method

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
Marcel Hibbe 2022-12-14 17:57:14 +01:00 committed by Andy Scherzinger
parent da8148a134
commit eff4b912bd
No known key found for this signature in database
GPG Key ID: 6CADC7E3523C308B

View File

@ -235,17 +235,17 @@ public class PushUtils {
List<User> users = userManager.getUsers().blockingGet();
for (User user : users) {
if (!user.getScheduledForDeletion()) {
Map<String, String> nextcloudRegisterPushMap = new HashMap<>();
nextcloudRegisterPushMap.put("format", "json");
nextcloudRegisterPushMap.put("pushTokenHash", pushTokenHash);
nextcloudRegisterPushMap.put("devicePublicKey", devicePublicKeyBase64);
nextcloudRegisterPushMap.put("proxyServer", proxyServer);
for (User user : users) {
if (!user.getScheduledForDeletion()) {
Map<String, String> nextcloudRegisterPushMap = new HashMap<>();
nextcloudRegisterPushMap.put("format", "json");
nextcloudRegisterPushMap.put("pushTokenHash", pushTokenHash);
nextcloudRegisterPushMap.put("devicePublicKey", devicePublicKeyBase64);
nextcloudRegisterPushMap.put("proxyServer", proxyServer);
registerDeviceWithNextcloud(ncApi, nextcloudRegisterPushMap, token, user);
}
registerDeviceWithNextcloud(ncApi, nextcloudRegisterPushMap, token, user);
}
}
}
} else {
@ -260,9 +260,9 @@ public class PushUtils {
String credentials = ApiUtils.getCredentials(user.getUsername(), user.getToken());
ncApi.registerDeviceForNotificationsWithNextcloud(
credentials,
ApiUtils.getUrlNextcloudPush(user.getBaseUrl()),
nextcloudRegisterPushMap)
credentials,
ApiUtils.getUrlNextcloudPush(user.getBaseUrl()),
nextcloudRegisterPushMap)
.subscribe(new Observer<PushRegistrationOverall>() {
@Override
public void onSubscribe(@NonNull Disposable d) {
@ -338,26 +338,31 @@ public class PushUtils {
pushConfigurationState.setUserPublicKey(proxyMap.get("userPublicKey"));
pushConfigurationState.setUsesRegularPass(Boolean.FALSE);
userManager.updatePushState(user.getId(), pushConfigurationState).subscribe(new SingleObserver<Integer>() {
@Override
public void onSubscribe(Disposable d) {
// unused atm
}
if (user.getId() != null) {
userManager.updatePushState(user.getId(), pushConfigurationState).subscribe(new SingleObserver<Integer>() {
@Override
public void onSubscribe(Disposable d) {
// unused atm
}
@Override
public void onSuccess(Integer integer) {
eventBus.post(new EventStatus(UserIdUtils.INSTANCE.getIdForUser(user),
EventStatus.EventType.PUSH_REGISTRATION,
true));
}
@Override
public void onSuccess(Integer integer) {
eventBus.post(new EventStatus(UserIdUtils.INSTANCE.getIdForUser(user),
EventStatus.EventType.PUSH_REGISTRATION,
true));
}
@Override
public void onError(Throwable e) {
eventBus.post(new EventStatus(UserIdUtils.INSTANCE.getIdForUser(user),
EventStatus.EventType.PUSH_REGISTRATION,
false));
}
});
} else {
Log.e(TAG, "failed to update updatePushStateForUser. user.getId() was null");
}
@Override
public void onError(Throwable e) {
eventBus.post(new EventStatus(UserIdUtils.INSTANCE.getIdForUser(user),
EventStatus.EventType.PUSH_REGISTRATION,
false));
}
});
}
private Key readKeyFromString(boolean readPublicKey, String keyString) {