]> source.dussan.org Git - sonarqube.git/commitdiff
fix quality flaw (removed non necessary try/catch)
authorStephane Gamard <stephane.gamard@searchbox.com>
Fri, 4 Jul 2014 06:54:15 +0000 (08:54 +0200)
committerStephane Gamard <stephane.gamard@searchbox.com>
Fri, 4 Jul 2014 07:34:00 +0000 (09:34 +0200)
sonar-server/src/main/java/org/sonar/server/search/BaseIndex.java

index 6dd84f084dfe852b4f853c1979ee3271c7cf2d90..fda4682574aa7a35f137db20dc50419f28f156dd 100644 (file)
@@ -201,21 +201,22 @@ public abstract class BaseIndex<DOMAIN, DTO extends Dto<KEY>, KEY extends Serial
   @Override
   public Date getLastSynchronization() {
     Date date;
-    try {
-      SearchRequestBuilder request = getClient().prepareSearch(this.getIndexName())
-        .setTypes(this.getIndexType())
-        .setQuery(QueryBuilders.matchAllQuery())
-        .setSize(0)
-        .addAggregation(AggregationBuilders.max("latest")
-          .field(BaseNormalizer.UPDATED_AT_FIELD));
+    SearchRequestBuilder request = getClient().prepareSearch(this.getIndexName())
+      .setTypes(this.getIndexType())
+      .setQuery(QueryBuilders.matchAllQuery())
+      .setSize(0)
+      .addAggregation(AggregationBuilders.max("latest")
+        .field(BaseNormalizer.UPDATED_AT_FIELD));
 
-      SearchResponse response = request.get();
+    SearchResponse response = request.get();
 
-      Max max = (Max) response.getAggregations().get("latest");
-      return new DateTime(Double.valueOf(max.getValue()).longValue()).toDate();
-    } catch (Exception e) {
+    Max max = (Max) response.getAggregations().get("latest");
+    if (Double.isNaN(max.getValue())) {
       date = new Date(0L);
+    } else {
+      date = new DateTime(Double.valueOf(max.getValue()).longValue()).toDate();
     }
+
     LOG.info("Index {}:{} has last update of {}", this.getIndexName(), this.getIndexType(), date);
     return date;
   }