From 3e243829512cf5d818a2dc9d167277026fe4240a Mon Sep 17 00:00:00 2001 From: Stephane Gamard Date: Fri, 4 Jul 2014 08:54:15 +0200 Subject: [PATCH] fix quality flaw (removed non necessary try/catch) --- .../org/sonar/server/search/BaseIndex.java | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/sonar-server/src/main/java/org/sonar/server/search/BaseIndex.java b/sonar-server/src/main/java/org/sonar/server/search/BaseIndex.java index 6dd84f084df..fda4682574a 100644 --- a/sonar-server/src/main/java/org/sonar/server/search/BaseIndex.java +++ b/sonar-server/src/main/java/org/sonar/server/search/BaseIndex.java @@ -201,21 +201,22 @@ public abstract class BaseIndex, 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; } -- 2.39.5