From 2a54dfc8fa78ff8f2eaf8072d1b7447b5720f297 Mon Sep 17 00:00:00 2001 From: Duarte Meneses Date: Thu, 13 Aug 2015 17:19:32 +0200 Subject: [PATCH] Improve quality --- .../java/org/sonar/runner/impl/ServerConnection.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/sonar-runner-api/src/main/java/org/sonar/runner/impl/ServerConnection.java b/sonar-runner-api/src/main/java/org/sonar/runner/impl/ServerConnection.java index eb1002f..5b306bd 100644 --- a/sonar-runner-api/src/main/java/org/sonar/runner/impl/ServerConnection.java +++ b/sonar-runner-api/src/main/java/org/sonar/runner/impl/ServerConnection.java @@ -143,11 +143,8 @@ class ServerConnection { try { return downloadString(fullUrl, isCacheEnable); } catch (HttpRequest.HttpRequestException e) { - if (e.getCause() instanceof ConnectException || e.getCause() instanceof UnknownHostException || - e.getCause() instanceof java.net.SocketTimeoutException) { - if (isCacheEnable) { - return fallbackToCache(fullUrl, e); - } + if (isCausedByConnection(e) && isCacheEnable) { + return fallbackToCache(fullUrl, e); } logger.error(MessageFormat.format(SONAR_SERVER_CAN_NOT_BE_REACHED, serverUrl)); @@ -155,6 +152,11 @@ class ServerConnection { } } + private boolean isCausedByConnection(Exception e) { + return e.getCause() instanceof ConnectException || e.getCause() instanceof UnknownHostException || + e.getCause() instanceof java.net.SocketTimeoutException; + } + private String fallbackToCache(String fullUrl, HttpRequest.HttpRequestException originalException) { logger.info(MessageFormat.format(SONAR_SERVER_CAN_NOT_BE_REACHED + ", trying cache", serverUrl)); -- 2.39.5