Skip to content

Commit

Permalink
(Sonar) Fixed finding: "String literals should not be duplicated"
Browse files Browse the repository at this point in the history
  • Loading branch information
pixeebot[bot] authored May 22, 2024
1 parent d770603 commit 62e7106
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -611,9 +611,9 @@ public static LoginUrlInfo parseLoginDataUrl(String prefix, String dataString) t
} else if (value.startsWith("password" + LOGIN_URL_DATA_KEY_VALUE_SEPARATOR)) {
loginUrlInfo.password = URLDecoder.decode(
value.substring(("password" + LOGIN_URL_DATA_KEY_VALUE_SEPARATOR).length()));
} else if (value.startsWith("server" + LOGIN_URL_DATA_KEY_VALUE_SEPARATOR)) {
} else if (value.startsWith(SERVER + LOGIN_URL_DATA_KEY_VALUE_SEPARATOR)) {
loginUrlInfo.serverAddress = URLDecoder.decode(
value.substring(("server" + LOGIN_URL_DATA_KEY_VALUE_SEPARATOR).length()));
value.substring((SERVER + LOGIN_URL_DATA_KEY_VALUE_SEPARATOR).length()));
}
}

Expand Down Expand Up @@ -1680,7 +1680,7 @@ private void completeLoginFlow(String response, int status) {
try {
JSONObject jsonObject = new JSONObject(response);

String server = jsonObject.getString("server");
String server = jsonObject.getString(SERVER);
String loginName = jsonObject.getString("loginName");
String appPassword = jsonObject.getString("appPassword");

Expand Down Expand Up @@ -1723,4 +1723,6 @@ public void onSavedCertificate() {
public void onFailedSavingCertificate() {
DisplayUtils.showSnackMessage(this, R.string.ssl_validator_not_saved);
}

private static final String SERVER = "server";
}
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ public OCUpload[] getCurrentAndPendingUploadsForAccount(final @NonNull String ac
"==" + UploadResult.DELAYED_FOR_CHARGING.getValue() +
" OR " + ProviderTableMeta.UPLOADS_LAST_RESULT +
"==" + UploadResult.DELAYED_IN_POWER_SAVE_MODE.getValue() +
" ) AND " + ProviderTableMeta.UPLOADS_ACCOUNT_NAME + "== ?",
AND_1 + ProviderTableMeta.UPLOADS_ACCOUNT_NAME + "== ?",
accountName);
}

Expand All @@ -588,7 +588,7 @@ public List<OCUpload> getCurrentAndPendingUploadsForAccountPageAscById(final lon
"==" + UploadResult.DELAYED_FOR_CHARGING.getValue() +
" OR " + ProviderTableMeta.UPLOADS_LAST_RESULT +
"==" + UploadResult.DELAYED_IN_POWER_SAVE_MODE.getValue() +
" ) AND " + ProviderTableMeta.UPLOADS_ACCOUNT_NAME + "== ?";
AND_1 + ProviderTableMeta.UPLOADS_ACCOUNT_NAME + "== ?";
return getUploadPage(afterId, false, selection, accountName);
}

Expand All @@ -605,7 +605,7 @@ public OCUpload[] getFailedUploads() {
"==" + UploadResult.DELAYED_FOR_CHARGING.getValue() +
" OR " + ProviderTableMeta.UPLOADS_LAST_RESULT +
"==" + UploadResult.DELAYED_IN_POWER_SAVE_MODE.getValue() +
" ) AND " + ProviderTableMeta.UPLOADS_LAST_RESULT +
AND_1 + ProviderTableMeta.UPLOADS_LAST_RESULT +
"!= " + UploadResult.VIRUS_DETECTED.getValue()
, String.valueOf(UploadStatus.UPLOAD_FAILED.value));
}
Expand Down Expand Up @@ -895,4 +895,6 @@ public int getValue() {
}

}

private static final String AND_1 = " ) AND ";
}
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ private RemoteOperationResult encryptedCreateV1(OCFile parent, OwnCloudClient cl
token = null;
} else {
// TODO E2E: do better
throw new RuntimeException("Could not unlock folder!");
throw new RuntimeException(COULD_NOT_UNLOCK_FOLDER);
}
}

Expand All @@ -204,13 +204,13 @@ private RemoteOperationResult encryptedCreateV1(OCFile parent, OwnCloudClient cl
}
} else {
// revert to sane state in case of any error
Log_OC.e(TAG, remotePath + " hasn't been created");
Log_OC.e(TAG, remotePath + HASN_T_BEEN_CREATED);
}

return result;
} catch (Exception e) {
if (!EncryptionUtils.unlockFolderV1(parent, client, token).isSuccess()) {
throw new RuntimeException("Could not clean up after failing folder creation!", e);
throw new RuntimeException(COULD_NOT_CLEAN_UP_AFTER_FAILING_FOLDER_CREATION, e);
}

// remove folder
Expand All @@ -224,7 +224,7 @@ private RemoteOperationResult encryptedCreateV1(OCFile parent, OwnCloudClient cl
).execute(client);

if (!removeResult.isSuccess()) {
throw new RuntimeException("Could not clean up after failing folder creation!");
throw new RuntimeException(COULD_NOT_CLEAN_UP_AFTER_FAILING_FOLDER_CREATION);
}
}

Expand All @@ -237,7 +237,7 @@ private RemoteOperationResult encryptedCreateV1(OCFile parent, OwnCloudClient cl

if (!unlockFolderResult.isSuccess()) {
// TODO E2E: do better
throw new RuntimeException("Could not unlock folder!");
throw new RuntimeException(COULD_NOT_UNLOCK_FOLDER);
}
}
}
Expand Down Expand Up @@ -321,7 +321,7 @@ private RemoteOperationResult encryptedCreateV2(OCFile parent, OwnCloudClient cl
token = null;
} else {
// TODO E2E: do better
throw new RuntimeException("Could not unlock folder!");
throw new RuntimeException(COULD_NOT_UNLOCK_FOLDER);
}

RemoteOperationResult remoteFolderOperationResult = new ReadFolderRemoteOperation(encryptedRemotePath)
Expand All @@ -342,15 +342,15 @@ private RemoteOperationResult encryptedCreateV2(OCFile parent, OwnCloudClient cl
}
} else {
// revert to sane state in case of any error
Log_OC.e(TAG, remotePath + " hasn't been created");
Log_OC.e(TAG, remotePath + HASN_T_BEEN_CREATED);
}

return result;
} catch (Exception e) {
// TODO remove folder

if (!EncryptionUtils.unlockFolder(parent, client, token).isSuccess()) {
throw new RuntimeException("Could not clean up after failing folder creation!", e);
throw new RuntimeException(COULD_NOT_CLEAN_UP_AFTER_FAILING_FOLDER_CREATION, e);
}

// remove folder
Expand All @@ -363,7 +363,7 @@ private RemoteOperationResult encryptedCreateV2(OCFile parent, OwnCloudClient cl
true).execute(client);

if (!removeResult.isSuccess()) {
throw new RuntimeException("Could not clean up after failing folder creation!");
throw new RuntimeException(COULD_NOT_CLEAN_UP_AFTER_FAILING_FOLDER_CREATION);
}
}

Expand All @@ -376,7 +376,7 @@ private RemoteOperationResult encryptedCreateV2(OCFile parent, OwnCloudClient cl

if (!unlockFolderResult.isSuccess()) {
// TODO E2E: do better
throw new RuntimeException("Could not unlock folder!");
throw new RuntimeException(COULD_NOT_UNLOCK_FOLDER);
}
}
}
Expand Down Expand Up @@ -483,7 +483,7 @@ private RemoteOperationResult normalCreate(OwnCloudClient client) {
createdRemoteFolder = (RemoteFile) remoteFolderOperationResult.getData().get(0);
saveFolderInDB();
} else {
Log_OC.e(TAG, remotePath + " hasn't been created");
Log_OC.e(TAG, remotePath + HASN_T_BEEN_CREATED);
}

return result;
Expand All @@ -500,7 +500,7 @@ private void onCreateRemoteFolderOperationFinish(RemoteOperationResult result) {
if (result.isSuccess()) {
saveFolderInDB();
} else {
Log_OC.e(TAG, remotePath + " hasn't been created");
Log_OC.e(TAG, remotePath + HASN_T_BEEN_CREATED);
}
}

Expand Down Expand Up @@ -540,4 +540,10 @@ private void saveFolderInDB() {
public String getRemotePath() {
return remotePath;
}

private static final String COULD_NOT_UNLOCK_FOLDER = "Could not unlock folder!";

private static final String HASN_T_BEEN_CREATED = " hasn't been created";

private static final String COULD_NOT_CLEAN_UP_AFTER_FAILING_FOLDER_CREATION = "Could not clean up after failing folder creation!";
}

0 comments on commit 62e7106

Please sign in to comment.