]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9802 fix NPE in EsStatusCheck
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Sun, 24 Sep 2017 19:59:12 +0000 (21:59 +0200)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Tue, 26 Sep 2017 21:49:38 +0000 (23:49 +0200)
server/sonar-server/src/main/java/org/sonar/server/health/EsStatusCheck.java
server/sonar-server/src/test/java/org/sonar/server/health/EsStatusNodeCheckTest.java

index 7c4c0bb57a1f526eb174538bdf8833f9905abb5a..a6947fb63bfd799731348690068fcd793b8118ae 100644 (file)
@@ -37,7 +37,7 @@ abstract class EsStatusCheck {
     .setStatus(Health.Status.RED)
     .addCause("Elasticsearch status is RED")
     .build();
-  private static final Health RED_HEALTH_EXCEPTION_OCCURED = newHealthCheckBuilder()
+  private static final Health RED_HEALTH_UNAVAILABLE = newHealthCheckBuilder()
     .setStatus(Health.Status.RED)
     .addCause("Elasticsearch status is RED (unavailable)")
     .build();
@@ -51,6 +51,9 @@ abstract class EsStatusCheck {
   Health checkEsStatus() {
     try {
       ClusterHealthStatus esStatus = esClient.prepareClusterStats().get().getStatus();
+      if (esStatus == null) {
+        return RED_HEALTH_UNAVAILABLE;
+      }
       switch (esStatus) {
         case GREEN:
           return Health.GREEN;
@@ -63,7 +66,7 @@ abstract class EsStatusCheck {
       }
     } catch (Exception e) {
       LOG.error("Failed to query ES status", e);
-      return RED_HEALTH_EXCEPTION_OCCURED;
+      return RED_HEALTH_UNAVAILABLE;
     }
   }
 }
index 2530be657db8a3243832ba08a692d830a093e153..4c91adf083ef834471f910d0d65eab3629d815f4 100644 (file)
@@ -38,7 +38,7 @@ public class EsStatusNodeCheckTest {
   @Test
   public void check_ignores_NodeHealth_arg_and_returns_RED_with_cause_if_an_exception_occurs_checking_ES_cluster_status() {
     EsClient esClient = Mockito.mock(EsClient.class);
-    when(esClient.prepareClusterStats()).thenThrow(new RuntimeException("Faking an exception occuring while using the EsClient"));
+    when(esClient.prepareClusterStats()).thenThrow(new RuntimeException("Faking an exception occurring while using the EsClient"));
 
     Health health = new EsStatusNodeCheck(esClient).check();