Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d88ed2d9 authored by Jonathan Klee's avatar Jonathan Klee
Browse files

Merge branch '5400-r-fix-as-npe' into 'v1-oreo'

Fix NPE detected by AS code inspector

See merge request !129
parents 69ae974f d2553576
Loading
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -24,6 +24,8 @@
 */
package foundation.e.drive.operations;

import android.util.Log;

import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.network.WebdavUtils;
import com.owncloud.android.lib.common.operations.OperationCancelledException;
@@ -74,7 +76,13 @@ class DownloadFileRemoteOperation extends RemoteOperation {
        File tmpFile = new File(getTmpPath());
        /// perform the download
        try {
            tmpFile.getParentFile().mkdirs();
            File parentFile = tmpFile.getParentFile();
            if (parentFile == null) {
                Log.e(TAG, "getParentFile() returned null. Returning to prevent a NPE");
                return new RemoteOperationResult(RemoteOperationResult.ResultCode.UNKNOWN_ERROR);
            }

            parentFile.mkdirs();
            int status = downloadFile(client, tmpFile);
            result = new RemoteOperationResult(isSuccess(status), mGet);
            Log_OC.i(TAG, "Download of " + mRemotePath + " to " + getTmpPath() + ": " +
+20 −5
Original line number Diff line number Diff line
@@ -65,8 +65,14 @@ public class ListFileRemoteOperation extends RemoteOperation {
            SyncedFolder syncedFolder = mSyncedFolderIterator.next();

            //if folder is media type() && is an hidden folder then ignore it
            String fileName = CommonUtils.getFileNameFromPath(syncedFolder.getRemoteFolder());
            if (fileName == null) {
                Log.e(TAG, "getFileNameFromPath() returned null. Returning to prevent a NPE");
                return new RemoteOperationResult(RemoteOperationResult.ResultCode.UNKNOWN_ERROR);
            }

            if(syncedFolder.isMediaType()
                && CommonUtils.getFileNameFromPath(syncedFolder.getRemoteFolder()).startsWith(".")){
                && fileName.startsWith(".")){
                mSyncedFolderIterator.remove();
                continue;
            }
@@ -107,8 +113,13 @@ public class ListFileRemoteOperation extends RemoteOperation {

                            //if remoteFile is in a "media" folder and its name start with "."
                            // then ignore it
                            if(syncedFolder.isMediaType()
                                && CommonUtils.getFileNameFromPath( remoteFile.getRemotePath() ).startsWith(".") ){
                            fileName = CommonUtils.getFileNameFromPath(remoteFile.getRemotePath());
                            if (fileName == null) {
                                Log.e(TAG, "getFileNameFromPath() returned null. Returning to prevent NPE");
                                return new RemoteOperationResult(RemoteOperationResult.ResultCode.UNKNOWN_ERROR);
                            }

                            if(syncedFolder.isMediaType() && fileName.startsWith(".") ){
                                continue;
                            }
                            if( remoteFile.getMimeType().equals("DIR") ) {
@@ -140,9 +151,13 @@ public class ListFileRemoteOperation extends RemoteOperation {
                    syncedFolder.setToSync(true);
                    //If there is no remote file, then try to delete local one if empty. Finally remove Synced Folder from DB.
                    File localFolder = new File(syncedFolder.getLocalFolder());
                    if(localFolder.exists() && localFolder.listFiles().length == 0){
                    if (localFolder.exists()) {
                       File[] arrayFiles = localFolder.listFiles();
                        if (arrayFiles != null && arrayFiles.length == 0) {
                            localFolder.delete();
                        }
                    }

                    if( !localFolder.exists() ) {
                        if (syncedFolder.getId() > this.initialFolderNumber/*-1*/) { //does the synced folder has been persisted?
                            //remove it from DB
+18 −3
Original line number Diff line number Diff line
@@ -166,8 +166,17 @@ public class ObserverService extends Service implements OnRemoteOperationListene
     */
    private void deleteOldestCrashlogs(){
        Log.i(TAG, "deleteOldestCrashLogs()");
        File[] fileToRemove = getExternalFilesDir(ServiceExceptionHandler.CRASH_LOG_FOLDER)
                .listFiles(new CrashlogsFileFilter());
        File externalFilesDir = getExternalFilesDir(ServiceExceptionHandler.CRASH_LOG_FOLDER);
        if (externalFilesDir == null) {
            Log.e(TAG, "getExternalFilesDir() returned null. Returning to prevent a NPE");
            return;
        }

        File[] fileToRemove = externalFilesDir.listFiles(new CrashlogsFileFilter());
        if (fileToRemove == null) {
            Log.e(TAG, "getExternalFilesDir() returned null. Returning to prevent a NPE");
            return;
        }

        int counter = 0;
        for (File file : fileToRemove) {
@@ -551,7 +560,13 @@ public class ObserverService extends Service implements OnRemoteOperationListene
            Log.d(TAG, "SyncedFolder :"+syncedFolder.getLibelle()+", "+syncedFolder.getLocalFolder()+", "+syncedFolder.getLastModified()+", "+syncedFolder.isScanLocal()+", "+syncedFolder.getId() );

            //Check it's not a hidden file
            if (syncedFolder.isMediaType() && CommonUtils.getFileNameFromPath(syncedFolder.getLocalFolder()).startsWith(".")){
            String fileName = CommonUtils.getFileNameFromPath(syncedFolder.getLocalFolder());
            if (fileName == null) {
                Log.e(TAG, "getFileNameFromPath() returned null. Returning to prevent a NPE");
                return;
            }

            if (syncedFolder.isMediaType() && fileName.startsWith(".")){
                iterator.remove();
                continue;
            }
+5 −0
Original line number Diff line number Diff line
@@ -96,6 +96,11 @@ public class ResetService extends Service {

    private void removeCachedFiles() {
        File[] cachedFiles =  this.getApplicationContext().getExternalCacheDir().listFiles();
        if (cachedFiles == null) {
            Log.e(TAG, "listFiles() returned null. Returning to prevent a NPE");
            return;
        }

        for (File f : cachedFiles) {
            f.delete();
        }