Skip to content

Commit a69a0fd

Browse files
committed
Fix lint
- remove redundant exception handling Signed-off-by: ZetaTom <70907959+ZetaTom@users.noreply.github.com>
1 parent 80eca68 commit a69a0fd

4 files changed

Lines changed: 50 additions & 66 deletions

File tree

library/src/androidTest/java/com/owncloud/android/lib/resources/files/FilesDownloadLimitIT.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class FilesDownloadLimitIT : AbstractIT() {
3535
}
3636

3737
@Test
38+
@Suppress("Detekt.MagicNumber")
3839
fun downloadLimit() {
3940
val share = createTestShare()
4041
val limit = 5

library/src/main/java/com/nextcloud/android/lib/resources/files/GetFilesDownloadLimitRemoteOperation.kt

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ class GetFilesDownloadLimitRemoteOperation
2626
) : OCSRemoteOperation<List<FileDownloadLimit>>() {
2727
@Deprecated("Deprecated in Java")
2828
override fun run(client: OwnCloudClient): RemoteOperationResult<List<FileDownloadLimit>> {
29-
var result: RemoteOperationResult<List<FileDownloadLimit>>
30-
var propFindMethod: PropFindMethod? = null
29+
val result: RemoteOperationResult<List<FileDownloadLimit>>
3130
val propSet = DavPropertyNameSet()
3231
val depth = if (subfiles) DavConstants.DEPTH_1 else DavConstants.DEPTH_0
3332

@@ -36,33 +35,29 @@ class GetFilesDownloadLimitRemoteOperation
3635
Namespace.getNamespace(WebdavEntry.NAMESPACE_NC)
3736
)
3837

39-
try {
40-
propFindMethod = PropFindMethod(client.getFilesDavUri(remotePath), propSet, depth)
38+
val propFindMethod = PropFindMethod(client.getFilesDavUri(remotePath), propSet, depth)
4139

42-
val status = client.executeMethod(propFindMethod)
40+
val status = client.executeMethod(propFindMethod)
4341

44-
if (status == HttpStatus.SC_MULTI_STATUS || status == HttpStatus.SC_OK) {
45-
val response = propFindMethod.responseBodyAsMultiStatus
42+
if (status == HttpStatus.SC_MULTI_STATUS || status == HttpStatus.SC_OK) {
43+
val response = propFindMethod.responseBodyAsMultiStatus
4644

47-
val fileDownloadLimits =
48-
response.responses.flatMap {
49-
val webdavEntry = WebdavEntry(it, client.filesDavUri.encodedPath!!)
50-
webdavEntry.fileDownloadLimit
51-
}
45+
val fileDownloadLimits =
46+
response.responses.flatMap {
47+
val webdavEntry = WebdavEntry(it, client.filesDavUri.encodedPath!!)
48+
webdavEntry.fileDownloadLimit
49+
}
5250

53-
result = RemoteOperationResult(true, propFindMethod)
54-
result.resultData = fileDownloadLimits
55-
} else {
56-
result = RemoteOperationResult(false, propFindMethod)
57-
client.exhaustResponse(propFindMethod.responseBodyAsStream)
58-
}
59-
} catch (e: Exception) {
60-
result = RemoteOperationResult(e)
61-
Log_OC.e(TAG, "Exception while reading download limit", e)
62-
} finally {
63-
propFindMethod?.releaseConnection()
51+
result = RemoteOperationResult(true, propFindMethod)
52+
result.resultData = fileDownloadLimits
53+
} else {
54+
Log_OC.e(TAG, "Failed to get download limit")
55+
result = RemoteOperationResult(false, propFindMethod)
56+
client.exhaustResponse(propFindMethod.responseBodyAsStream)
6457
}
6558

59+
propFindMethod.releaseConnection()
60+
6661
return result
6762
}
6863

library/src/main/java/com/nextcloud/android/lib/resources/files/RemoveFilesDownloadLimitRemoteOperation.kt

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,23 @@ class RemoveFilesDownloadLimitRemoteOperation(
1818
val token: String
1919
) : OCSRemoteOperation<Void>() {
2020
override fun run(client: NextcloudClient): RemoteOperationResult<Void> {
21-
var result: RemoteOperationResult<Void>
22-
var deleteMethod: DeleteMethod? = null
23-
24-
try {
25-
val url = client.baseUri.toString() + String.format(FILES_DOWNLOAD_LIMIT_ENDPOINT, token) + JSON_FORMAT
26-
deleteMethod = DeleteMethod(url, true)
27-
28-
val status = deleteMethod.execute(client)
29-
30-
if (status == HttpStatus.SC_OK) {
31-
result = RemoteOperationResult(true, deleteMethod)
32-
} else {
33-
result = RemoteOperationResult(false, deleteMethod)
34-
Log_OC.e(TAG, "Failed to remove download limit")
35-
Log_OC.e(TAG, "*** status code: " + status + "; response: " + deleteMethod.getResponseBodyAsString())
36-
}
37-
} catch (e: Exception) {
38-
result = RemoteOperationResult(e)
39-
Log_OC.e(TAG, "Exception while removing download limit", e)
40-
} finally {
41-
deleteMethod?.releaseConnection()
21+
val result: RemoteOperationResult<Void>
22+
23+
val url = client.baseUri.toString() + String.format(FILES_DOWNLOAD_LIMIT_ENDPOINT, token) + JSON_FORMAT
24+
val deleteMethod = DeleteMethod(url, true)
25+
26+
val status = deleteMethod.execute(client)
27+
28+
if (status == HttpStatus.SC_OK) {
29+
result = RemoteOperationResult(true, deleteMethod)
30+
} else {
31+
result = RemoteOperationResult(false, deleteMethod)
32+
Log_OC.e(TAG, "Failed to remove download limit")
33+
Log_OC.e(TAG, "*** status code: " + status + "; response: " + deleteMethod.getResponseBodyAsString())
4234
}
4335

36+
deleteMethod.releaseConnection()
37+
4438
return result
4539
}
4640

library/src/main/java/com/nextcloud/android/lib/resources/files/SetFilesDownloadLimitRemoteOperation.kt

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,30 +20,24 @@ class SetFilesDownloadLimitRemoteOperation(
2020
val limit: Int
2121
) : OCSRemoteOperation<Void>() {
2222
override fun run(client: NextcloudClient): RemoteOperationResult<Void> {
23-
var result: RemoteOperationResult<Void>
24-
var putMethod: PutMethod? = null
25-
26-
try {
27-
val url = client.baseUri.toString() + String.format(FILES_DOWNLOAD_LIMIT_ENDPOINT, token)
28-
val jsonRequestBody = JSONRequestBody("limit", limit.toString())
29-
putMethod = PutMethod(url, true, jsonRequestBody.get())
30-
31-
val status = putMethod.execute(client)
32-
33-
if (status == HttpStatus.SC_OK) {
34-
result = RemoteOperationResult(true, putMethod)
35-
} else {
36-
result = RemoteOperationResult(false, putMethod)
37-
Log_OC.e(TAG, "Failed to set download limit")
38-
Log_OC.e(TAG, "*** status code: " + status + "; response: " + putMethod.getResponseBodyAsString())
39-
}
40-
} catch (e: Exception) {
41-
result = RemoteOperationResult(e)
42-
Log_OC.e(TAG, "Exception while setting download limit", e)
43-
} finally {
44-
putMethod?.releaseConnection()
23+
val result: RemoteOperationResult<Void>
24+
25+
val url = client.baseUri.toString() + String.format(FILES_DOWNLOAD_LIMIT_ENDPOINT, token)
26+
val jsonRequestBody = JSONRequestBody("limit", limit.toString())
27+
val putMethod = PutMethod(url, true, jsonRequestBody.get())
28+
29+
val status = putMethod.execute(client)
30+
31+
if (status == HttpStatus.SC_OK) {
32+
result = RemoteOperationResult(true, putMethod)
33+
} else {
34+
result = RemoteOperationResult(false, putMethod)
35+
Log_OC.e(TAG, "Failed to set download limit")
36+
Log_OC.e(TAG, "*** status code: " + status + "; response: " + putMethod.getResponseBodyAsString())
4537
}
4638

39+
putMethod.releaseConnection()
40+
4741
return result
4842
}
4943

0 commit comments

Comments
 (0)