From 19a2b39fe69d0d5287a1f91b4c12784e6d113888 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Mon, 4 Nov 2024 11:22:28 +0100 Subject: [PATCH] check nullable field in checkForChanges function Signed-off-by: alperozturk --- .../SynchronizeFolderOperation.java | 36 ++++++++++++------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/com/owncloud/android/operations/SynchronizeFolderOperation.java b/app/src/main/java/com/owncloud/android/operations/SynchronizeFolderOperation.java index c4e4bf05c06a..8515e1e744ea 100644 --- a/app/src/main/java/com/owncloud/android/operations/SynchronizeFolderOperation.java +++ b/app/src/main/java/com/owncloud/android/operations/SynchronizeFolderOperation.java @@ -159,33 +159,43 @@ private RemoteOperationResult checkForChanges(OwnCloudClient client) throws Oper throw new OperationCancelledException(); } - // remote request ReadFileRemoteOperation operation = new ReadFileRemoteOperation(mRemotePath); RemoteOperationResult result = operation.execute(client); + if (result.isSuccess()) { - OCFile remoteFolder = FileStorageUtils.fillOCFile((RemoteFile) result.getData().get(0)); + var data = result.getData().get(0); + if (!(data instanceof RemoteFile remoteFile)) { + return new RemoteOperationResult<>(ResultCode.FILE_NOT_FOUND); + } - // check if remote and local folder are different - mRemoteFolderChanged = !(remoteFolder.getEtag().equalsIgnoreCase(mLocalFolder.getEtag())); + OCFile remoteFolder = FileStorageUtils.fillOCFile(remoteFile); + String localETag = mLocalFolder.getEtag(); + if (mLocalFolder == null || localETag == null) { + return new RemoteOperationResult<>(ResultCode.LOCAL_FILE_NOT_FOUND); + } - result = new RemoteOperationResult(ResultCode.OK); + String remoteETag = remoteFolder.getEtag(); + if (remoteETag == null) { + return new RemoteOperationResult<>(ResultCode.FILE_NOT_FOUND); + } - Log_OC.i(TAG, "Checked " + user.getAccountName() + mRemotePath + " : " + - (mRemoteFolderChanged ? "changed" : "not changed")); + mRemoteFolderChanged = !(remoteETag.equalsIgnoreCase(localETag)); + result = new RemoteOperationResult<>(ResultCode.OK); + String logMessage = "Checked " + user.getAccountName() + mRemotePath + " : " + (mRemoteFolderChanged ? "changed" : "not changed"); + Log_OC.i(TAG, logMessage); } else { - // check failed if (result.getCode() == ResultCode.FILE_NOT_FOUND) { removeLocalFolder(); } + + String logMessage = "Checked " + user.getAccountName() + mRemotePath + " : " + result.getLogMessage(); + if (result.isException()) { - Log_OC.e(TAG, "Checked " + user.getAccountName() + mRemotePath + " : " + - result.getLogMessage(), result.getException()); - } else { - Log_OC.e(TAG, "Checked " + user.getAccountName() + mRemotePath + " : " + - result.getLogMessage()); + logMessage += result.getException(); } + Log_OC.e(TAG, logMessage); } return result;