diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2014-06-17 12:08:51 +0200 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@sonarsource.com> | 2014-06-19 09:32:34 +0200 |
commit | 1e1547ee8108e348485e010fd6f9bd74a8465cfa (patch) | |
tree | 16b1bfc882361468cf40571eacb337b1a0042036 /sonar-batch/src | |
parent | 66e2fb658541cb5412a1d05f61c4e731ab7c74aa (diff) | |
download | sonarqube-1e1547ee8108e348485e010fd6f9bd74a8465cfa.tar.gz sonarqube-1e1547ee8108e348485e010fd6f9bd74a8465cfa.zip |
Fix some quality flaws
Diffstat (limited to 'sonar-batch/src')
-rw-r--r-- | sonar-batch/src/main/java/org/sonar/batch/index/MeasurePersister.java | 18 |
1 files changed, 7 insertions, 11 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/MeasurePersister.java b/sonar-batch/src/main/java/org/sonar/batch/index/MeasurePersister.java index 2edf522df7a..e317fe80566 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/index/MeasurePersister.java +++ b/sonar-batch/src/main/java/org/sonar/batch/index/MeasurePersister.java @@ -31,12 +31,13 @@ import org.sonar.api.rule.RuleKey; import org.sonar.api.rules.Rule; import org.sonar.api.rules.RuleFinder; import org.sonar.api.technicaldebt.batch.Characteristic; -import org.sonar.api.utils.SonarException; import org.sonar.batch.index.Cache.Entry; import org.sonar.batch.scan.measure.MeasureCache; import org.sonar.core.persistence.DbSession; import org.sonar.core.persistence.MyBatis; +import javax.annotation.Nullable; + public final class MeasurePersister implements ScanPersister { private final MyBatis mybatis; private final RuleFinder ruleFinder; @@ -73,15 +74,15 @@ public final class MeasurePersister implements ScanPersister { session.commit(); } catch (Exception e) { - throw new SonarException("Unable to save some measures", e); + throw new IllegalStateException("Unable to save some measures", e); } finally { MyBatis.closeQuietly(session); } } @VisibleForTesting - static boolean shouldPersistMeasure(Resource resource, Measure measure) { - return measure.getPersistenceMode().useDatabase() && + static boolean shouldPersistMeasure(@Nullable Resource resource, @Nullable Measure measure) { + return resource != null && measure != null && measure.getPersistenceMode().useDatabase() && !(ResourceUtils.isEntity(resource) && measure.isBestValue()) && isMeasureNotEmpty(measure); } @@ -114,12 +115,7 @@ public final class MeasurePersister implements ScanPersister { model.setCharacteristicId(characteristic.id()); } model.setPersonId(measure.getPersonId()); - Double value = measure.getValue(); - if (value != null) { - model.setValue(value); - } else { - model.setValue(null); - } + model.setValue(measure.getValue()); if (measure instanceof RuleMeasure) { RuleMeasure ruleMeasure = (RuleMeasure) measure; model.setRulePriority(ruleMeasure.getSeverity()); @@ -127,7 +123,7 @@ public final class MeasurePersister implements ScanPersister { if (ruleKey != null) { Rule ruleWithId = ruleFinder.findByKey(ruleKey); if (ruleWithId == null) { - throw new SonarException("Can not save a measure with unknown rule " + ruleMeasure); + throw new IllegalStateException("Can not save a measure with unknown rule " + ruleMeasure); } model.setRuleId(ruleWithId.getId()); } |