From c0c2f694581775860688e821179b9c495095d287 Mon Sep 17 00:00:00 2001 From: "sonarqube-agent[bot]" <210722872+sonarqube-agent[bot]@users.noreply.github.com> Date: Tue, 1 Sep 2026 05:07:11 +0000 Subject: [PATCH] fix: Address 3 SonarQube issues Fixed issues: - AZnrNg4uQgHvdlpusoNV for java:S127 rule - AZnrNg4uQgHvdlpusoNW for java:S1192 rule - AZmJX1qbU8CNVV2bgk-B for java:S2638 rule Generated by SonarQube Agent (task: c436b639-2d78-4f49-ae1b-ad9f4c2e9386) --- .../java/com/sonar/orchestrator/http/HttpCall.java | 12 ++++++------ .../java/com/sonar/orchestrator/http/HttpClient.java | 4 +++- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/sonar-orchestrator-http/src/main/java/com/sonar/orchestrator/http/HttpCall.java b/sonar-orchestrator-http/src/main/java/com/sonar/orchestrator/http/HttpCall.java index 2ed7234f..933501b6 100644 --- a/sonar-orchestrator-http/src/main/java/com/sonar/orchestrator/http/HttpCall.java +++ b/sonar-orchestrator-http/src/main/java/com/sonar/orchestrator/http/HttpCall.java @@ -50,6 +50,7 @@ public class HttpCall { private static final String ADMIN_PASSWORD = "admin"; private static final String DEFAULT_USER_AGENT = "Orchestrator"; + private static final String CANNOT_CALL_FORMAT = CANNOT_CALL_FORMAT; private final OkHttpClient okClient; private final HttpUrl baseUrl; @@ -141,9 +142,8 @@ public HttpCall setParam(String key, @Nullable String value) { public HttpCall setParams(String key1, @Nullable String value1, String... otherKeysAndNames) { checkArgument(otherKeysAndNames.length % 2 == 0, "Expecting even number of arguments: %s", Arrays.toString(otherKeysAndNames)); parameters.put(key1, value1); - for (int i = 0; i < otherKeysAndNames.length; i++) { + for (int i = 0; i < otherKeysAndNames.length; i += 2) { parameters.put(otherKeysAndNames[i], otherKeysAndNames[i + 1]); - i++; } return this; } @@ -196,10 +196,10 @@ public void downloadToFile(File file) { try { doDownloadToFile(okRequest, file); } catch (IOException e2) { - throw new IllegalStateException(format("Can not call %s", okRequest.url()), e2); + throw new IllegalStateException(format(CANNOT_CALL_FORMAT, okRequest.url()), e2); } } catch (IOException e) { - throw new IllegalStateException(format("Can not call %s", okRequest.url()), e); + throw new IllegalStateException(format(CANNOT_CALL_FORMAT, okRequest.url()), e); } } @@ -221,10 +221,10 @@ public File downloadToDirectory(File dir) { try { return doDownloadToDirectory(dir, okRequest); } catch (IOException e2) { - throw new IllegalStateException(format("Can not call %s", okRequest.url()), e2); + throw new IllegalStateException(format(CANNOT_CALL_FORMAT, okRequest.url()), e2); } } catch (IOException e) { - throw new IllegalStateException(format("Can not call %s", okRequest.url()), e); + throw new IllegalStateException(format(CANNOT_CALL_FORMAT, okRequest.url()), e); } } diff --git a/sonar-orchestrator-http/src/main/java/com/sonar/orchestrator/http/HttpClient.java b/sonar-orchestrator-http/src/main/java/com/sonar/orchestrator/http/HttpClient.java index abc89eba..2364682c 100644 --- a/sonar-orchestrator-http/src/main/java/com/sonar/orchestrator/http/HttpClient.java +++ b/sonar-orchestrator-http/src/main/java/com/sonar/orchestrator/http/HttpClient.java @@ -29,6 +29,8 @@ import okhttp3.Response; import okhttp3.Route; +import javax.annotation.Nullable; + import static org.apache.commons.lang3.StringUtils.isEmpty; public class HttpClient { @@ -88,7 +90,7 @@ private ProxyAuthenticator(String login, String password) { } @Override - public Request authenticate(Route route, Response response) { + public Request authenticate(@Nullable Route route, Response response) { if (HttpURLConnection.HTTP_PROXY_AUTH == response.code()) { String credential = Credentials.basic(login, password); return response.request().newBuilder().header("Proxy-Authorization", credential).build();