From fc156a72bc46337ecc0163fbba72624f28e4fa24 Mon Sep 17 00:00:00 2001 From: Andy Scherzinger Date: Mon, 26 Aug 2019 13:31:33 +0200 Subject: [PATCH] codacy: A class which only has private constructors should be final codacy: Avoid throwing raw exception types. Signed-off-by: Andy Scherzinger --- .../android/operations/UploadException.java | 31 +++++++++++++++++++ .../operations/UploadFileOperation.java | 10 +++--- .../data/activities/ActivityRepositories.java | 6 ++-- .../data/files/FileRepositories.java | 4 +-- 4 files changed, 40 insertions(+), 11 deletions(-) create mode 100644 src/main/java/com/owncloud/android/operations/UploadException.java diff --git a/src/main/java/com/owncloud/android/operations/UploadException.java b/src/main/java/com/owncloud/android/operations/UploadException.java new file mode 100644 index 0000000000..49feb5f03c --- /dev/null +++ b/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 . + */ + +package com.owncloud.android.operations; + +class UploadException extends Exception { + UploadException() { + super(); + } + + UploadException(String message) { + super(message); + } +} diff --git a/src/main/java/com/owncloud/android/operations/UploadFileOperation.java b/src/main/java/com/owncloud/android/operations/UploadFileOperation.java index 3d8f181686..1ffe1dcecc 100644 --- a/src/main/java/com/owncloud/android/operations/UploadFileOperation.java +++ b/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) { diff --git a/src/main/java/com/owncloud/android/ui/activities/data/activities/ActivityRepositories.java b/src/main/java/com/owncloud/android/ui/activities/data/activities/ActivityRepositories.java index 8949b17196..c341875ae1 100644 --- a/src/main/java/com/owncloud/android/ui/activities/data/activities/ActivityRepositories.java +++ b/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); } - } - diff --git a/src/main/java/com/owncloud/android/ui/activities/data/files/FileRepositories.java b/src/main/java/com/owncloud/android/ui/activities/data/files/FileRepositories.java index 5c6d51ca87..073559d99a 100644 --- a/src/main/java/com/owncloud/android/ui/activities/data/files/FileRepositories.java +++ b/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