]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-4366 Protect against metric where hidden=null
authorJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Tue, 8 Apr 2014 15:49:28 +0000 (17:49 +0200)
committerJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Tue, 8 Apr 2014 15:49:33 +0000 (17:49 +0200)
sonar-server/src/main/java/org/sonar/server/qualitygate/QualityGates.java
sonar-server/src/test/java/org/sonar/server/qualitygate/QualityGatesTest.java

index 5f51aa76eb8f834e08caff46e59b870ff0f20195..17df95cedc797c6db87651f66cd5a947d7d7a982 100644 (file)
@@ -22,6 +22,7 @@ package org.sonar.server.qualitygate;
 import com.google.common.base.Predicate;
 import com.google.common.base.Strings;
 import com.google.common.collect.Collections2;
+import org.apache.commons.lang.BooleanUtils;
 import org.apache.commons.lang.StringUtils;
 import org.apache.ibatis.session.SqlSession;
 import org.elasticsearch.common.collect.Lists;
@@ -284,7 +285,7 @@ public class QualityGates {
   }
 
   private boolean isAlertable(Metric metric) {
-    return !metric.isDataType() && !metric.isHidden() && !CoreMetrics.ALERT_STATUS.equals(metric) && ValueType.RATING != metric.getType();
+    return !metric.isDataType() && BooleanUtils.isFalse(metric.isHidden()) && !CoreMetrics.ALERT_STATUS.equals(metric) && ValueType.RATING != metric.getType();
   }
 
   private boolean isDefault(QualityGateDto qGate) {
index 31fb5d557161fb8e0f6dc50e79c48ffcb2ffc5cc..6fa7412d47d0a9abb2583e674e3c4e78533b9a0f 100644 (file)
@@ -560,13 +560,15 @@ public class QualityGatesTest {
     when(dataMetric.isDataType()).thenReturn(true);
     Metric hiddenMetric = mock(Metric.class);
     when(hiddenMetric.isHidden()).thenReturn(true);
+    Metric nullHiddenMetric = mock(Metric.class);
+    when(nullHiddenMetric.isHidden()).thenReturn(null);
     Metric alertMetric = CoreMetrics.ALERT_STATUS;
     Metric ratingMetric = mock(Metric.class);
     when(ratingMetric.getType()).thenReturn(ValueType.RATING);
     Metric classicMetric = mock(Metric.class);
     when(classicMetric.getType()).thenReturn(ValueType.BOOL);
     when(metricFinder.findAll()).thenReturn(ImmutableList.of(
-      dataMetric, hiddenMetric, alertMetric, ratingMetric, classicMetric));
+      dataMetric, hiddenMetric, nullHiddenMetric, alertMetric, ratingMetric, classicMetric));
     assertThat(qGates.gateMetrics()).hasSize(1).containsOnly(classicMetric);
   }
 }