From cf3c13a41eb8135422b6b9c8d3541b7bec2d6857 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Lievremont Date: Tue, 8 Apr 2014 17:49:28 +0200 Subject: [PATCH] SONAR-4366 Protect against metric where hidden=null --- .../main/java/org/sonar/server/qualitygate/QualityGates.java | 3 ++- .../java/org/sonar/server/qualitygate/QualityGatesTest.java | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/sonar-server/src/main/java/org/sonar/server/qualitygate/QualityGates.java b/sonar-server/src/main/java/org/sonar/server/qualitygate/QualityGates.java index 5f51aa76eb8..17df95cedc7 100644 --- a/sonar-server/src/main/java/org/sonar/server/qualitygate/QualityGates.java +++ b/sonar-server/src/main/java/org/sonar/server/qualitygate/QualityGates.java @@ -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) { diff --git a/sonar-server/src/test/java/org/sonar/server/qualitygate/QualityGatesTest.java b/sonar-server/src/test/java/org/sonar/server/qualitygate/QualityGatesTest.java index 31fb5d55716..6fa7412d47d 100644 --- a/sonar-server/src/test/java/org/sonar/server/qualitygate/QualityGatesTest.java +++ b/sonar-server/src/test/java/org/sonar/server/qualitygate/QualityGatesTest.java @@ -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); } } -- 2.39.5