From 2f028ac0795685946c10fe1c609fadd1d91e0c74 Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Mon, 11 Apr 2022 17:57:44 +0200 Subject: [PATCH 1/2] Fix NullPointerException in SynchronizationService.onRemoteOperationFinish() - Create callerOperationResultData to store remoteOperationResult's data and allow to check if not null before to try to retrieve data - use callerOperationResultData variable further in the method to avoid to read again data from OperationResult. --- .../e/drive/services/SynchronizationService.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/foundation/e/drive/services/SynchronizationService.java b/app/src/main/java/foundation/e/drive/services/SynchronizationService.java index afc77d70..45000455 100644 --- a/app/src/main/java/foundation/e/drive/services/SynchronizationService.java +++ b/app/src/main/java/foundation/e/drive/services/SynchronizationService.java @@ -32,6 +32,7 @@ import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult; import java.lang.ref.WeakReference; +import java.util.ArrayList; import java.util.Collection; import java.util.Hashtable; import java.util.concurrent.ConcurrentLinkedDeque; @@ -152,7 +153,8 @@ public class SynchronizationService extends Service implements OnRemoteOperation } } else { String operationClassName = callerOperation.getClass().getSimpleName(); - if (callerOperation instanceof UploadFileOperation) { + final ArrayList callerOperationResultData = result.getData(); + if (callerOperation instanceof UploadFileOperation && callerOperationResultData != null) { final Float relativeQuota = (Float) result.getData().get(1); if (relativeQuota >= 99.0) { addNotification(getString(R.string.notif_quota_nearlyReached_title), getString(R.string.notif_quota_99Plus_text)); @@ -175,8 +177,8 @@ public class SynchronizationService extends Service implements OnRemoteOperation break; case UNKNOWN_ERROR: if (callerOperation instanceof UploadFileOperation) { - if(result.getData() != null) { - int rowAffected = DbHelper.forceFoldertoBeRescan(((Long) result.getData().get(0)).intValue(), getApplicationContext()); + if (callerOperationResultData != null) { + int rowAffected = DbHelper.forceFoldertoBeRescan(((Long) callerOperationResultData.get(0)).intValue(), getApplicationContext()); Log.e(TAG, " Upload failed for unknown reason.\n Force folder to be rescan next time (row affected) :" + rowAffected); } else { Log.w(TAG, "result.getData() for UploadFileOperation returned null"); @@ -187,8 +189,8 @@ public class SynchronizationService extends Service implements OnRemoteOperation break; case FORBIDDEN: if (callerOperation instanceof UploadFileOperation) { - if (result.getData() != null) { - int rowAffected = DbHelper.forceFoldertoBeRescan(((Long) result.getData().get(0)).intValue(), getApplicationContext()); + if (callerOperationResultData != null) { + int rowAffected = DbHelper.forceFoldertoBeRescan(((Long) callerOperationResultData.get(0)).intValue(), getApplicationContext()); Log.e(TAG, " Upload: Forbidden : Can't get syncedFileState, no remote path defined. Force folder to be rescan next time (row affected) :" + rowAffected); } else { Log.w(TAG, "result.getData() for UploadFileOperation returned null"); @@ -210,7 +212,6 @@ public class SynchronizationService extends Service implements OnRemoteOperation //Case specific to DownloadFileOperation Log.e(TAG, operationClassName+" : Sync_conflict: File is already up to date"); break; - } } } -- GitLab From b18a8a0e8664d6cb1e6dbed084c8327236d344b1 Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Mon, 11 Apr 2022 18:18:48 +0200 Subject: [PATCH 2/2] add if condition on resultData's size when required --- .../e/drive/services/SynchronizationService.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/foundation/e/drive/services/SynchronizationService.java b/app/src/main/java/foundation/e/drive/services/SynchronizationService.java index 45000455..8583768a 100644 --- a/app/src/main/java/foundation/e/drive/services/SynchronizationService.java +++ b/app/src/main/java/foundation/e/drive/services/SynchronizationService.java @@ -154,7 +154,8 @@ public class SynchronizationService extends Service implements OnRemoteOperation } else { String operationClassName = callerOperation.getClass().getSimpleName(); final ArrayList callerOperationResultData = result.getData(); - if (callerOperation instanceof UploadFileOperation && callerOperationResultData != null) { + if (callerOperation instanceof UploadFileOperation && callerOperationResultData != null + && callerOperationResultData.size() > 1) { final Float relativeQuota = (Float) result.getData().get(1); if (relativeQuota >= 99.0) { addNotification(getString(R.string.notif_quota_nearlyReached_title), getString(R.string.notif_quota_99Plus_text)); @@ -177,7 +178,7 @@ public class SynchronizationService extends Service implements OnRemoteOperation break; case UNKNOWN_ERROR: if (callerOperation instanceof UploadFileOperation) { - if (callerOperationResultData != null) { + if (callerOperationResultData != null && callerOperationResultData.size() > 0) { int rowAffected = DbHelper.forceFoldertoBeRescan(((Long) callerOperationResultData.get(0)).intValue(), getApplicationContext()); Log.e(TAG, " Upload failed for unknown reason.\n Force folder to be rescan next time (row affected) :" + rowAffected); } else { @@ -189,7 +190,7 @@ public class SynchronizationService extends Service implements OnRemoteOperation break; case FORBIDDEN: if (callerOperation instanceof UploadFileOperation) { - if (callerOperationResultData != null) { + if (callerOperationResultData != null && callerOperationResultData.size() > 0) { int rowAffected = DbHelper.forceFoldertoBeRescan(((Long) callerOperationResultData.get(0)).intValue(), getApplicationContext()); Log.e(TAG, " Upload: Forbidden : Can't get syncedFileState, no remote path defined. Force folder to be rescan next time (row affected) :" + rowAffected); } else { -- GitLab