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();