From e409b5afb647f5af6fbe26618bb8448040560f59 Mon Sep 17 00:00:00 2001 From: "David A. Velasco" Date: Fri, 12 Dec 2014 13:30:55 +0100 Subject: [PATCH] Fixed a couple of null pointers --- .../operations/SynchronizeFileOperation.java | 23 +++++++++++++--------- .../operations/SynchronizeFolderOperation.java | 2 ++ 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/com/owncloud/android/operations/SynchronizeFileOperation.java b/src/com/owncloud/android/operations/SynchronizeFileOperation.java index 6cff2b70..72cb22be 100644 --- a/src/com/owncloud/android/operations/SynchronizeFileOperation.java +++ b/src/com/owncloud/android/operations/SynchronizeFileOperation.java @@ -98,9 +98,10 @@ public class SynchronizeFileOperation extends SyncOperation { * Useful to include this operation as part of the synchronization of a folder (or a full account), avoiding the * repetition of fetch operations (both in local database or remote server). * - * At least data from local cache must be provided. If you don't have them, use the other constructor. + * At least one of localFile or serverFile MUST NOT BE NULL. If you don't have none of them, use the other + * constructor. * - * @param localFile Data of file (just) retrieved from local cache/database. MUSTN't be null. + * @param localFile Data of file (just) retrieved from local cache/database. * @param serverFile Data of file (just) retrieved from a remote server. If null, will be * retrieved from network by the operation when executed. * @param account ownCloud account holding the file. @@ -117,7 +118,16 @@ public class SynchronizeFileOperation extends SyncOperation { mLocalFile = localFile; mServerFile = serverFile; - mRemotePath = localFile.getRemotePath(); // this will crash if localFile == null; use the other constructor + if (mLocalFile != null) { + mRemotePath = mLocalFile.getRemotePath(); + if (mServerFile != null && !mServerFile.getRemotePath().equals(mRemotePath)) { + throw new IllegalArgumentException("serverFile and localFile do not correspond to the same OC file"); + } + } else if (mServerFile != null) { + mRemotePath = mServerFile.getRemotePath(); + } else { + throw new IllegalArgumentException("Both serverFile and localFile are NULL"); + } mAccount = account; mSyncFileContents = syncFileContents; mContext = context; @@ -153,12 +163,7 @@ public class SynchronizeFileOperation extends SyncOperation { boolean allowUploads, Context context) { - mLocalFile = localFile; - mServerFile = serverFile; - mRemotePath = localFile.getRemotePath(); // this will crash if localFile == null; use the other constructor - mAccount = account; - mSyncFileContents = syncFileContents; - mContext = context; + this(localFile, serverFile, account, syncFileContents, context); mAllowUploads = allowUploads; } diff --git a/src/com/owncloud/android/operations/SynchronizeFolderOperation.java b/src/com/owncloud/android/operations/SynchronizeFolderOperation.java index 926e57f8..3f640974 100644 --- a/src/com/owncloud/android/operations/SynchronizeFolderOperation.java +++ b/src/com/owncloud/android/operations/SynchronizeFolderOperation.java @@ -116,6 +116,7 @@ public class SynchronizeFolderOperation extends SyncOperation { mAccount = account; mContext = context; mRemoteFolderChanged = false; + mFilesForDirectDownload = new Vector(); mFilesToSyncContentsWithoutUpload = new Vector(); mFavouriteFilesToSyncContents = new Vector(); mFoldersToWalkDown = new Vector(); @@ -269,6 +270,7 @@ public class SynchronizeFolderOperation extends SyncOperation { + " changed - starting update of local data "); List updatedFiles = new Vector(folderAndFiles.size() - 1); + mFilesForDirectDownload.clear(); mFilesToSyncContentsWithoutUpload.clear(); mFavouriteFilesToSyncContents.clear(); mFoldersToWalkDown.clear(); -- 2.11.0