浏览代码

codacy: avoid declaring a variable if it is unreferenced before a possible exit point.

AndyScherzinger 6 年之前
父节点
当前提交
eafa49c822

+ 2 - 1
src/main/java/com/owncloud/android/authentication/AuthenticatorActivity.java

@@ -547,7 +547,6 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
         if (dataString.length() < prefix.length()) {
             throw new IllegalArgumentException("Invalid login URL detected");
         }
-        LoginUrlInfo loginUrlInfo = new LoginUrlInfo();
 
         // format is basically xxx://login/server:xxx&user:xxx&password while all variables are optional
         String data = dataString.substring(prefix.length());
@@ -560,6 +559,8 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
             throw new IllegalArgumentException("Illegal number of login URL elements detected: " + values.length);
         }
 
+        LoginUrlInfo loginUrlInfo = new LoginUrlInfo();
+
         for (String value : values) {
             if (value.startsWith("user" + LOGIN_URL_DATA_KEY_VALUE_SEPARATOR)) {
                 loginUrlInfo.username = URLDecoder.decode(

+ 4 - 6
src/main/java/com/owncloud/android/files/services/FileUploader.java

@@ -571,12 +571,6 @@ public class FileUploader extends Service
                 mimeTypes = intent.getStringArrayExtra(KEY_MIME_TYPE);
             }
 
-            boolean forceOverwrite = intent.getBooleanExtra(KEY_FORCE_OVERWRITE, false);
-            int localAction = intent.getIntExtra(KEY_LOCAL_BEHAVIOUR, LOCAL_BEHAVIOUR_FORGET);
-
-            boolean isCreateRemoteFolder = intent.getBooleanExtra(KEY_CREATE_REMOTE_FOLDER, false);
-            int createdBy = intent.getIntExtra(KEY_CREATED_BY, UploadFileOperation.CREATED_BY_USER);
-
             if (intent.hasExtra(KEY_FILE) && files == null) {
                 Log_OC.e(TAG, "Incorrect array for OCFiles provided in upload intent");
                 return Service.START_NOT_STICKY;
@@ -611,6 +605,10 @@ public class FileUploader extends Service
             }
             // at this point variable "OCFile[] files" is loaded correctly.
 
+            boolean forceOverwrite = intent.getBooleanExtra(KEY_FORCE_OVERWRITE, false);
+            int localAction = intent.getIntExtra(KEY_LOCAL_BEHAVIOUR, LOCAL_BEHAVIOUR_FORGET);
+            boolean isCreateRemoteFolder = intent.getBooleanExtra(KEY_CREATE_REMOTE_FOLDER, false);
+            int createdBy = intent.getIntExtra(KEY_CREATED_BY, UploadFileOperation.CREATED_BY_USER);
             String uploadKey;
             UploadFileOperation newUpload;
             try {

+ 5 - 3
src/main/java/com/owncloud/android/jobs/FilesSyncJob.java

@@ -72,8 +72,6 @@ public class FilesSyncJob extends Job {
     @Override
     protected Result onRunJob(@NonNull Params params) {
         final Context context = MainApp.getAppContext();
-        final ContentResolver contentResolver = context.getContentResolver();
-        FileUploader.UploadRequester requester = new FileUploader.UploadRequester();
         PowerManager.WakeLock wakeLock = null;
 
         if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
@@ -83,7 +81,6 @@ public class FilesSyncJob extends Job {
         }
 
         PersistableBundleCompat bundle = params.getExtras();
-        final boolean skipCustom = bundle.getBoolean(SKIP_CUSTOM, false);
         final boolean overridePowerSaving = bundle.getBoolean(OVERRIDE_POWER_SAVING, false);
 
         // If we are in power save mode, better to postpone upload
@@ -92,13 +89,16 @@ public class FilesSyncJob extends Job {
             return Result.SUCCESS;
         }
 
+
         Resources resources = MainApp.getAppContext().getResources();
         boolean lightVersion = resources.getBoolean(R.bool.syncedFolder_light);
 
+        final boolean skipCustom = bundle.getBoolean(SKIP_CUSTOM, false);
         FilesSyncHelper.restartJobsIfNeeded();
         FilesSyncHelper.insertAllDBEntries(skipCustom);
 
         // Create all the providers we'll need
+        final ContentResolver contentResolver = context.getContentResolver();
         final FilesystemDataProvider filesystemDataProvider = new FilesystemDataProvider(contentResolver);
         SyncedFolderProvider syncedFolderProvider = new SyncedFolderProvider(contentResolver);
 
@@ -106,6 +106,8 @@ public class FilesSyncJob extends Job {
         SimpleDateFormat sFormatter = new SimpleDateFormat("yyyy:MM:dd HH:mm:ss", currentLocale);
         sFormatter.setTimeZone(TimeZone.getTimeZone(TimeZone.getDefault().getID()));
 
+        FileUploader.UploadRequester requester = new FileUploader.UploadRequester();
+
         for (SyncedFolder syncedFolder : syncedFolderProvider.getSyncedFolders()) {
             if ((syncedFolder.isEnabled()) && (!skipCustom || MediaFolderType.CUSTOM != syncedFolder.getType())) {
                 for (String path : filesystemDataProvider.getFilesForUpload(syncedFolder.getLocalPath(),

+ 3 - 9
src/main/java/com/owncloud/android/operations/CopyFileOperation.java

@@ -1,4 +1,4 @@
-    /* ownCloud Android client application
+/*   ownCloud Android client application
  *   Copyright (C) 2012-2014 ownCloud Inc.
  *
  *   This program is free software: you can redistribute it and/or modify
@@ -12,7 +12,6 @@
  *
  *   You should have received a copy of the GNU General Public License
  *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
- *
  */
 
 package com.owncloud.android.operations;
@@ -36,10 +35,8 @@ public class CopyFileOperation extends SyncOperation {
 
     private String mSrcPath;
     private String mTargetParentPath;
-
     private OCFile mFile;
 
-
     /**
      * Constructor
      *
@@ -63,8 +60,6 @@ public class CopyFileOperation extends SyncOperation {
      */
     @Override
     protected RemoteOperationResult run(OwnCloudClient client) {
-        RemoteOperationResult result;
-
         /// 1. check copy validity
         if (mTargetParentPath.startsWith(mSrcPath)) {
             return new RemoteOperationResult(ResultCode.INVALID_COPY_INTO_DESCENDANT);
@@ -84,7 +79,8 @@ public class CopyFileOperation extends SyncOperation {
                 targetPath,
                 false
         );
-        result = operation.execute(client);
+
+        RemoteOperationResult result = operation.execute(client);
 
         /// 3. local copy
         if (result.isSuccess()) {
@@ -94,6 +90,4 @@ public class CopyFileOperation extends SyncOperation {
 
         return result;
     }
-
-
 }

+ 9 - 9
src/main/java/com/owncloud/android/operations/DownloadFileOperation.java

@@ -154,21 +154,21 @@ public class DownloadFileOperation extends RemoteOperation {
 
     @Override
     protected RemoteOperationResult run(OwnCloudClient client) {
-        RemoteOperationResult result;
-        File newFile;
-        boolean moved;
-        
-        /// download will be performed to a temporal file, then moved to the final location
-        File tmpFile = new File(getTmpPath());
-        
-        String tmpFolder =  getTmpFolder();
-        
         /// perform the download
         synchronized(mCancellationRequested) {
             if (mCancellationRequested.get()) {
                 return new RemoteOperationResult(new OperationCancelledException());
             }
         }
+
+        RemoteOperationResult result;
+        File newFile;
+        boolean moved;
+
+        /// download will be performed to a temporal file, then moved to the final location
+        File tmpFile = new File(getTmpPath());
+
+        String tmpFolder =  getTmpFolder();
         
         mDownloadOperation = new DownloadRemoteFileOperation(mFile.getRemotePath(), tmpFolder);
         Iterator<OnDatatransferProgressListener> listener = mDataTransferListeners.iterator();

+ 2 - 6
src/main/java/com/owncloud/android/operations/MoveFileOperation.java

@@ -1,4 +1,4 @@
-/**
+/*
  *   ownCloud Android client application
  *
  *   @author David A. Velasco
@@ -15,7 +15,6 @@
  *
  *   You should have received a copy of the GNU General Public License
  *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
- *
  */
 
 package com.owncloud.android.operations;
@@ -37,7 +36,6 @@ public class MoveFileOperation extends SyncOperation {
     
     private String mSrcPath;
     private String mTargetParentPath;
-    
     private OCFile mFile;
     
     /**
@@ -63,8 +61,6 @@ public class MoveFileOperation extends SyncOperation {
      */
     @Override
     protected RemoteOperationResult run(OwnCloudClient client) {
-        RemoteOperationResult result;
-        
         /// 1. check move validity
         if (mTargetParentPath.startsWith(mSrcPath)) {
             return new RemoteOperationResult(ResultCode.INVALID_MOVE_INTO_DESCENDANT);
@@ -84,7 +80,7 @@ public class MoveFileOperation extends SyncOperation {
                 targetPath, 
                 false
         );
-        result = operation.execute(client);
+        RemoteOperationResult result = operation.execute(client);
         
         /// 3. local move
         if (result.isSuccess()) {

+ 4 - 5
src/main/java/com/owncloud/android/operations/SynchronizeFolderOperation.java

@@ -172,7 +172,6 @@ public class SynchronizeFolderOperation extends SyncOperation {
         Log_OC.d(TAG, "Checking changes in " + mAccount.name + mRemotePath);
 
         mRemoteFolderChanged = true;
-        RemoteOperationResult result;
         
         if (mCancellationRequested.get()) {
             throw new OperationCancelledException();
@@ -180,7 +179,7 @@ public class SynchronizeFolderOperation extends SyncOperation {
         
         // remote request
         ReadRemoteFileOperation operation = new ReadRemoteFileOperation(mRemotePath);
-        result = operation.execute(client);
+        RemoteOperationResult result = operation.execute(client);
         if (result.isSuccess()) {
             OCFile remoteFolder = FileStorageUtils.fillOCFile((RemoteFile) result.getData().get(0));
 
@@ -261,8 +260,6 @@ public class SynchronizeFolderOperation extends SyncOperation {
      * @param folderAndFiles Remote folder and children files in Folder
      */
     private void synchronizeData(List<Object> folderAndFiles) throws OperationCancelledException {
-        FileDataStorageManager storageManager = getStorageManager();
-        
         // parse data from remote folder
         OCFile remoteFolder = FileStorageUtils.fillOCFile((RemoteFile) folderAndFiles.get(0));
         remoteFolder.setParentId(mLocalFolder.getParentId());
@@ -271,7 +268,6 @@ public class SynchronizeFolderOperation extends SyncOperation {
         Log_OC.d(TAG, "Remote folder " + mLocalFolder.getRemotePath()
                 + " changed - starting update of local data ");
 
-        List<OCFile> updatedFiles = new Vector<>(folderAndFiles.size() - 1);
         mFilesForDirectDownload.clear();
         mFilesToSyncContents.clear();
 
@@ -279,6 +275,9 @@ public class SynchronizeFolderOperation extends SyncOperation {
             throw new OperationCancelledException();
         }
 
+        FileDataStorageManager storageManager = getStorageManager();
+        List<OCFile> updatedFiles = new Vector<>(folderAndFiles.size() - 1);
+
         // get current data about local contents of the folder to synchronize
         List<OCFile> localFiles = storageManager.getFolderContent(mLocalFolder, false);
         Map<String, OCFile> localFilesMap = new HashMap<>(localFiles.size());

+ 1 - 2
src/main/java/com/owncloud/android/providers/FileContentProvider.java

@@ -92,12 +92,11 @@ public class FileContentProvider extends ContentProvider {
 
     @Override
     public int delete(@NonNull Uri uri, String where, String[] whereArgs) {
-        int count;
-
         if (isCallerNotAllowed()) {
             return -1;
         }
 
+        int count;
         SQLiteDatabase db = mDbHelper.getWritableDatabase();
         db.beginTransaction();
         try {

+ 4 - 5
src/main/java/com/owncloud/android/syncadapter/FileSyncAdapter.java

@@ -141,9 +141,6 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter {
             SyncResult syncResult) {
 
         mCancellation = false;
-        /* When 'true' the process was requested by the user through the user interface;
-       when 'false', it was requested automatically by the system */
-        boolean mIsManualSync = extras.getBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, false);
         mFailedResultsCounter = 0;
         mLastFailedResult = null;
         mConflictsFound = 0;
@@ -170,7 +167,10 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter {
         Log_OC.d(TAG, "Synchronization of ownCloud account " + account.name + " starting");
         sendLocalBroadcast(EVENT_FULL_SYNC_START, null, null);  // message to signal the start
                                                                 // of the synchronization to the UI
-        
+
+        /* When 'true' the process was requested by the user through the user interface;
+           when 'false', it was requested automatically by the system */
+        boolean mIsManualSync = extras.getBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, false);
         try {
             updateOCVersion();
             mCurrentSyncTime = System.currentTimeMillis();
@@ -182,7 +182,6 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter {
                         "because cancellation request");
             }
             
-            
         } finally {
             // it's important making this although very unexpected errors occur;
             // that's the reason for the finally

+ 1 - 1
src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java

@@ -946,13 +946,13 @@ public abstract class DrawerActivity extends ToolbarActivity implements DisplayU
         Thread t = new Thread(new Runnable() {
             public void run() {
                 Context context = MainApp.getAppContext();
-                AccountManager mAccountMgr = AccountManager.get(context);
                 Account account = AccountUtils.getCurrentOwnCloudAccount(context);
 
                 if (account == null) {
                     return;
                 }
 
+                AccountManager mAccountMgr = AccountManager.get(context);
                 String userId = mAccountMgr.getUserData(account,
                         com.owncloud.android.lib.common.accounts.AccountUtils.Constants.KEY_USER_ID);
 

+ 1 - 2
src/main/java/com/owncloud/android/ui/dialog/SetupEncryptionDialogFragment.java

@@ -345,7 +345,6 @@ public class SetupEncryptionDialogFragment extends DialogFragment {
 
                 // Create public/private key pair
                 KeyPair keyPair = EncryptionUtils.generateKeyPair();
-                PrivateKey privateKey = keyPair.getPrivate();
 
                 // get user id
                 String userID;
@@ -369,13 +368,13 @@ public class SetupEncryptionDialogFragment extends DialogFragment {
 
                 if (result.isSuccess()) {
                     Log_OC.d(TAG, "public key success");
-
                     publicKey = (String) result.getData().get(0);
                 } else {
                     keyResult = KEY_FAILED;
                     return "";
                 }
 
+                PrivateKey privateKey = keyPair.getPrivate();
                 String privateKeyString = EncryptionUtils.encodeBytesToBase64String(privateKey.getEncoded());
                 String privatePemKeyString = EncryptionUtils.privateKeyToPEM(privateKey);
                 String encryptedPrivateKey = EncryptionUtils.encryptPrivateKey(privatePemKeyString,

+ 2 - 2
src/main/java/com/owncloud/android/ui/dialog/SyncedFolderPreferencesDialogFragment.java

@@ -83,14 +83,14 @@ public class SyncedFolderPreferencesDialogFragment extends DialogFragment {
     private AlertDialog behaviourDialog;
 
     public static SyncedFolderPreferencesDialogFragment newInstance(SyncedFolderDisplayItem syncedFolder, int section) {
-        SyncedFolderPreferencesDialogFragment dialogFragment = new SyncedFolderPreferencesDialogFragment();
-
         if (syncedFolder == null) {
             throw new IllegalArgumentException("SyncedFolder is mandatory but NULL!");
         }
 
         Bundle args = new Bundle();
         args.putParcelable(SYNCED_FOLDER_PARCELABLE, new SyncedFolderParcelable(syncedFolder, section));
+
+        SyncedFolderPreferencesDialogFragment dialogFragment = new SyncedFolderPreferencesDialogFragment();
         dialogFragment.setArguments(args);
         dialogFragment.setStyle(STYLE_NORMAL, R.style.Theme_ownCloud_Dialog);
 

+ 3 - 3
src/main/java/com/owncloud/android/ui/preview/PreviewImageFragment.java

@@ -439,12 +439,12 @@ public class PreviewImageFragment extends FileFragment {
         protected LoadImage doInBackground(OCFile... params) {
             Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND + Process.THREAD_PRIORITY_MORE_FAVORABLE);
 
-            Bitmap bitmapResult = null;
-            Drawable drawableResult = null;
-
             if (params.length != 1) {
                 return null;
             }
+
+            Bitmap bitmapResult = null;
+            Drawable drawableResult = null;
             OCFile ocFile = params[0];
             String storagePath = ocFile.getStoragePath();
             try {

+ 2 - 3
src/main/java/com/owncloud/android/utils/BitmapUtils.java

@@ -376,15 +376,14 @@ public class BitmapUtils {
     }
 
     public static Bitmap drawableToBitmap(Drawable drawable) {
-        Bitmap bitmap;
-
         if (drawable instanceof BitmapDrawable) {
             BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
             if (bitmapDrawable.getBitmap() != null) {
                 return bitmapDrawable.getBitmap();
             }
         }
-
+        
+        Bitmap bitmap;
         if (drawable.getIntrinsicWidth() <= 0 || drawable.getIntrinsicHeight() <= 0) {
             bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);
         } else {