Browse Source

codacy: A class which only has private constructors should be final
codacy: Avoid throwing raw exception types.

Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>

Andy Scherzinger 5 years ago
parent
commit
fc156a72bc

+ 31 - 0
src/main/java/com/owncloud/android/operations/UploadException.java

@@ -0,0 +1,31 @@
+/*
+ * Nextcloud Android client application
+ *
+ * @author Andy Scherzinger
+ * Copyright (C) 2019 Andy Scherzinger
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+package com.owncloud.android.operations;
+
+class UploadException extends Exception {
+    UploadException() {
+        super();
+    }
+
+    UploadException(String message) {
+        super(message);
+    }
+}

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

@@ -464,9 +464,9 @@ public class UploadFileOperation extends SyncOperation {
                 mUpload.setFolderUnlockToken(token);
                 uploadsStorageManager.updateUpload(mUpload);
             } else if (lockFileOperationResult.getHttpCode() == HttpStatus.SC_FORBIDDEN) {
-                throw new Exception("Forbidden! Please try again later.)");
+                throw new UploadException("Forbidden! Please try again later.)");
             } else {
-                throw new Exception("Unknown error!");
+                throw new UploadException("Unknown error!");
             }
 
             // Update metadata
@@ -498,10 +498,10 @@ public class UploadFileOperation extends SyncOperation {
                 metadata.getMetadata().getMetadataKeys().put(0, encryptedMetadataKey);
             } else {
                 // TODO error
-                throw new Exception("something wrong");
+                throw new UploadException("something wrong");
             }
 
-            /***** E2E *****/
+            /**** E2E *****/
 
             // check name collision
             checkNameCollision(client, metadata, parentFile.isEncrypted());
@@ -646,7 +646,7 @@ public class UploadFileOperation extends SyncOperation {
                 }
 
                 if (!uploadMetadataOperationResult.isSuccess()) {
-                    throw new Exception();
+                    throw new UploadException();
                 }
             }
         } catch (FileNotFoundException e) {

+ 2 - 4
src/main/java/com/owncloud/android/ui/activities/data/activities/ActivityRepositories.java

@@ -1,4 +1,4 @@
-/**
+/*
  *   Nextcloud Android client application
  *
  *   Copyright (C) 2018 Edvard Holst
@@ -20,7 +20,7 @@ package com.owncloud.android.ui.activities.data.activities;
 
 import androidx.annotation.NonNull;
 
-public class ActivityRepositories {
+public final class ActivityRepositories {
 
     private ActivityRepositories() {
         // No instance
@@ -29,6 +29,4 @@ public class ActivityRepositories {
     public static synchronized ActivitiesRepository getRepository(@NonNull ActivitiesServiceApi activitiesServiceApi) {
         return new RemoteActivitiesRepository(activitiesServiceApi);
     }
-
 }
-

+ 2 - 2
src/main/java/com/owncloud/android/ui/activities/data/files/FileRepositories.java

@@ -1,4 +1,4 @@
-/**
+/*
  *   Nextcloud Android client application
  *
  *   Copyright (C) 2018 Edvard Holst
@@ -20,7 +20,7 @@ package com.owncloud.android.ui.activities.data.files;
 
 import androidx.annotation.NonNull;
 
-public class FileRepositories {
+public final class FileRepositories {
 
     private FileRepositories() {
         // No instance