Browse Source

codacy: fix identical 'catch' branch

AndyScherzinger 6 years ago
parent
commit
559cdc70eb

+ 0 - 2
src/main/java/com/owncloud/android/datamodel/FilesystemDataProvider.java

@@ -222,8 +222,6 @@ public class FilesystemDataProvider {
 
             return crc.getValue();
 
-        } catch (FileNotFoundException e) {
-            return -1;
         } catch (IOException e) {
             return -1;
         }

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

@@ -612,13 +612,13 @@ public class FileUploader extends Service
             }
             // at this point variable "OCFile[] files" is loaded correctly.
 
-            String uploadKey = null;
-            UploadFileOperation newUpload = null;
+            String uploadKey;
+            UploadFileOperation newUpload;
             try {
-                for (int i = 0; i < files.length; i++) {
+                for (OCFile file : files) {
 
-                    OCUpload ocUpload = new OCUpload(files[i], account);
-                    ocUpload.setFileSize(files[i].getFileLength());
+                    OCUpload ocUpload = new OCUpload(file, account);
+                    ocUpload.setFileSize(file.getFileLength());
                     ocUpload.setForceOverwrite(forceOverwrite);
                     ocUpload.setCreateRemoteFolder(isCreateRemoteFolder);
                     ocUpload.setCreatedBy(createdBy);
@@ -630,7 +630,7 @@ public class FileUploader extends Service
 
                     newUpload = new UploadFileOperation(
                             account,
-                            files[i],
+                            file,
                             ocUpload,
                             forceOverwrite,
                             localAction,
@@ -649,7 +649,7 @@ public class FileUploader extends Service
 
                     Pair<String, String> putResult = mPendingUploads.putIfAbsent(
                             account.name,
-                            files[i].getRemotePath(),
+                            file.getRemotePath(),
                             newUpload
                     );
                     if (putResult != null) {

+ 4 - 10
src/main/java/com/owncloud/android/jobs/NotificationJob.java

@@ -60,7 +60,7 @@ public class NotificationJob extends Job {
 
     @NonNull
     @Override
-    protected Result onRunJob(Params params) {
+    protected Result onRunJob(@NonNull Params params) {
 
         Context context = getContext();
         PersistableBundleCompat persistableBundleCompat = getParams().getExtras();
@@ -68,7 +68,6 @@ public class NotificationJob extends Job {
         String signature = persistableBundleCompat.getString(KEY_NOTIFICATION_SIGNATURE, "");
 
         if (!TextUtils.isEmpty(subject) && !TextUtils.isEmpty(signature)) {
-
             try {
                 byte[] base64DecodedSubject = Base64.decode(subject, Base64.DEFAULT);
                 byte[] base64DecodedSignature = Base64.decode(signature, Base64.DEFAULT);
@@ -92,14 +91,10 @@ public class NotificationJob extends Job {
                         if (!decryptedPushMessage.getApp().equals("spreed")) {
                             sendNotification(decryptedPushMessage.getSubject(), signatureVerification.getAccount());
                         }
-
                     }
-                } catch (NoSuchAlgorithmException e1) {
-                    Log.d(TAG, "No proper algorithm to decrypt the message " + e1.getLocalizedMessage());
-                } catch (NoSuchPaddingException e1) {
-                    Log.d(TAG, "No proper padding to decrypt the message " + e1.getLocalizedMessage());
-                } catch (InvalidKeyException e1) {
-                    Log.d(TAG, "Invalid private key " + e1.getLocalizedMessage());
+                } catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException e1) {
+                    Log.d(TAG, "Error decrypting message " + e1.getClass().getName()
+                            + " " + e1.getLocalizedMessage());
                 }
             } catch (Exception exception) {
                 Log.d(TAG, "Something went very wrong" + exception.getLocalizedMessage());
@@ -136,5 +131,4 @@ public class NotificationJob extends Job {
 
         notificationManager.notify(0, notificationBuilder.build());
     }
-
 }

+ 2 - 20
src/main/java/com/owncloud/android/media/MediaService.java

@@ -470,29 +470,11 @@ public class MediaService extends Service implements OnCompletionListener, OnPre
                 mWifiLock.release();
             }
 
-        } catch (SecurityException e) {
-            Log_OC.e(TAG, "SecurityException playing " + mAccount.name + mFile.getRemotePath(), e);
+        } catch (SecurityException | IOException | IllegalStateException | IllegalArgumentException e) {
+            Log_OC.e(TAG, e.getClass().getSimpleName() + " playing " + mAccount.name + mFile.getRemotePath(), e);
             Toast.makeText(this, String.format(getString(R.string.media_err_security_ex), mFile.getFileName()),
                     Toast.LENGTH_LONG).show();
             processStopRequest(true);
-
-        } catch (IOException e) {
-            Log_OC.e(TAG, "IOException playing " + mAccount.name + mFile.getRemotePath(), e);
-            Toast.makeText(this, String.format(getString(R.string.media_err_io_ex), mFile.getFileName()),
-                    Toast.LENGTH_LONG).show();
-            processStopRequest(true);
-
-        } catch (IllegalStateException e) {
-            Log_OC.e(TAG, "IllegalStateException " + mAccount.name + mFile.getRemotePath(), e);
-            Toast.makeText(this, String.format(getString(R.string.media_err_unexpected), mFile.getFileName()),
-                    Toast.LENGTH_LONG).show();
-            processStopRequest(true);
-
-        } catch (IllegalArgumentException e) {
-            Log_OC.e(TAG, "IllegalArgumentException " + mAccount.name + mFile.getRemotePath(), e);
-            Toast.makeText(this, String.format(getString(R.string.media_err_unexpected), mFile.getFileName()),
-                    Toast.LENGTH_LONG).show();
-            processStopRequest(true);
         }
     }
 

+ 3 - 9
src/main/java/com/owncloud/android/ui/activity/NotificationsActivity.java

@@ -295,19 +295,13 @@ public class NotificationsActivity extends FileActivity {
                     // show error
                     runOnUiThread(() -> setEmptyContent(noResultsHeadline, getString(R.string.account_not_found)));
                 }
-            } catch (com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException e) {
-                Log_OC.e(TAG, "Account not found", e);
-            } catch (IOException e) {
-                Log_OC.e(TAG, "IO error", e);
-            } catch (OperationCanceledException e) {
-                Log_OC.e(TAG, "Operation has been canceled", e);
-            } catch (AuthenticatorException e) {
-                Log_OC.e(TAG, "Authentication Exception", e);
+            } catch (com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException | IOException |
+                    OperationCanceledException | AuthenticatorException e) {
+                Log_OC.e(TAG, "Error fetching notification data", e);
             }
         });
 
         t.start();
-
     }
 
     private void hideRefreshLayoutLoader() {

+ 1 - 7
src/main/java/com/owncloud/android/ui/dialog/SslUntrustedCertDialog.java

@@ -211,12 +211,7 @@ public class SslUntrustedCertDialog extends DialogFragment {
                 try {
                     NetworkUtils.addCertToKnownServersStore(m509Certificate, activity);   // TODO make this asynchronously, it can take some time
                     ((OnSslUntrustedCertListener)activity).onSavedCertificate();
-    
-                } catch (GeneralSecurityException e) {
-                    ((OnSslUntrustedCertListener)activity).onFailedSavingCertificate();
-                    Log_OC.e(TAG, "Server certificate could not be saved in the known-servers trust store ", e);
-                  
-                } catch (IOException e) {
+                } catch (GeneralSecurityException | IOException e) {
                     ((OnSslUntrustedCertListener)activity).onFailedSavingCertificate();
                     Log_OC.e(TAG, "Server certificate could not be saved in the known-servers trust store ", e);
                 }
@@ -239,5 +234,4 @@ public class SslUntrustedCertDialog extends DialogFragment {
     public interface CertificateViewAdapter {
         void updateCertificateView(View mView);
     }
-    
 }

+ 4 - 10
src/main/java/com/owncloud/android/ui/fragment/FileDetailActivitiesFragment.java

@@ -342,17 +342,11 @@ public class FileDetailActivitiesFragment extends Fragment implements ActivityLi
                 }
 
                 hideRefreshLayoutLoader(activity);
-            } catch (com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException e) {
-                Log_OC.e(TAG, "Account not found", e);
-            } catch (IOException e) {
-                Log_OC.e(TAG, "IO error", e);
-            } catch (OperationCanceledException e) {
-                Log_OC.e(TAG, "Operation has been canceled", e);
-            } catch (AuthenticatorException e) {
-                Log_OC.e(TAG, "Authentication Exception", e);
+            } catch (com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException | IOException |
+                    OperationCanceledException | AuthenticatorException e) {
+                Log_OC.e(TAG, "Error fetching file details activities", e);
             }
-        }
-        );
+        });
 
         t.start();
     }

+ 3 - 8
src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java

@@ -1332,14 +1332,9 @@ public class OCFileListFragment extends ExtendedListFragment implements
                 mAdapter.setFavoriteAttributeForItemID(event.remoteId, event.shouldFavorite);
             }
 
-        } catch (com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException e) {
-            Log_OC.e(TAG, "Account not found", e);
-        } catch (AuthenticatorException e) {
-            Log_OC.e(TAG, "Authentication failed", e);
-        } catch (IOException e) {
-            Log_OC.e(TAG, "IO error", e);
-        } catch (OperationCanceledException e) {
-            Log_OC.e(TAG, "Operation has been canceled", e);
+        } catch (com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException | AuthenticatorException
+                | IOException | OperationCanceledException e) {
+            Log_OC.e(TAG, "Error processing event", e);
         }
     }
 

+ 1 - 3
src/main/java/com/owncloud/android/utils/ConnectivityUtils.java

@@ -91,9 +91,7 @@ public class ConnectivityUtils {
                 Log_OC.e(TAG, "Error checking internet connection", e);
             } catch (com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException e) {
                 Log_OC.e(TAG, "Account not found", e);
-            } catch (OperationCanceledException e) {
-                Log_OC.e(TAG, e.getMessage());
-            } catch (AuthenticatorException e) {
+            } catch (OperationCanceledException | AuthenticatorException e) {
                 Log_OC.e(TAG, e.getMessage());
             }
         } else if (!Device.getNetworkType(context).equals(JobRequest.NetworkType.ANY)) {