aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2014-06-30 16:34:38 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2014-06-30 16:35:10 +0200
commitd44ef046f3dd7d59397c681cb79ebe3173d915bb (patch)
tree2851cb4dfd1c297e3e2cbdefb8b54d59f0ce06e0 /plugins
parentef9b3e8704be8de9f30c42f9e8034588309f6e16 (diff)
downloadsonarqube-d44ef046f3dd7d59397c681cb79ebe3173d915bb.tar.gz
sonarqube-d44ef046f3dd7d59397c681cb79ebe3173d915bb.zip
Fix some quality flaws
Diffstat (limited to 'plugins')
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/ManualMeasureDecorator.java7
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/VariationDecorator.java9
2 files changed, 14 insertions, 2 deletions
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/ManualMeasureDecorator.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/ManualMeasureDecorator.java
index 41c093c5994..1f9c5728c9d 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/ManualMeasureDecorator.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/ManualMeasureDecorator.java
@@ -24,6 +24,7 @@ import org.sonar.api.batch.DecoratorContext;
import org.sonar.api.batch.Phase;
import org.sonar.api.database.DatabaseSession;
import org.sonar.api.measures.Measure;
+import org.sonar.api.measures.Metric;
import org.sonar.api.measures.MetricFinder;
import org.sonar.api.resources.Project;
import org.sonar.api.resources.Resource;
@@ -56,7 +57,11 @@ public class ManualMeasureDecorator implements Decorator {
}
private Measure copy(ManualMeasure manualMeasure) {
- Measure measure = new Measure(metricFinder.findById(manualMeasure.getMetricId()));
+ Metric metric = metricFinder.findById(manualMeasure.getMetricId());
+ if (metric == null) {
+ throw new IllegalStateException("Unable to find manual metric with id: " + manualMeasure.getMetricId());
+ }
+ Measure measure = new Measure(metric);
measure.setValue(manualMeasure.getValue(), 5);
measure.setData(manualMeasure.getTextValue());
measure.setDescription(manualMeasure.getDescription());
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/VariationDecorator.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/VariationDecorator.java
index 8c8a6b622bf..19d1dd93207 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/VariationDecorator.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/VariationDecorator.java
@@ -107,7 +107,14 @@ public class VariationDecorator implements Decorator {
// for each measure, search equivalent past measure
for (Measure measure : context.getMeasures(MeasuresFilters.all())) {
// compare with past measure
- Integer metricId = measure.getMetric().getId() != null ? measure.getMetric().getId() : metricFinder.findByKey(measure.getMetric().getKey()).getId();
+ Integer metricId = measure.getMetric().getId();
+ if (metricId == null) {
+ Metric metric = metricFinder.findByKey(measure.getMetric().getKey());
+ if (metric == null) {
+ throw new IllegalStateException("Unknow metric with key: " + measure.getMetric().getKey());
+ }
+ metricId = metric.getId();
+ }
Characteristic characteristic = measure.getCharacteristic();
Integer characteristicId = characteristic != null ? characteristic.id() : null;
Integer personId = measure.getPersonId();