aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2014-04-02 16:45:38 +0200
committerJulien Lancelot <julien.lancelot@sonarsource.com>2014-04-02 16:45:38 +0200
commitfba37d16e7689b6a280646d5989c1336fc02b0af (patch)
treee70fac9a8dd3e2a393b3306484ea2113de08af06
parent374aa79930cccb1cbcea09e64954b5747e1c24e4 (diff)
downloadsonarqube-fba37d16e7689b6a280646d5989c1336fc02b0af.tar.gz
sonarqube-fba37d16e7689b6a280646d5989c1336fc02b0af.zip
SONAR-5056 Fix issue when reseting debt model and no rule is found
-rw-r--r--sonar-server/src/main/java/org/sonar/server/debt/DebtModelBackup.java22
1 files changed, 13 insertions, 9 deletions
diff --git a/sonar-server/src/main/java/org/sonar/server/debt/DebtModelBackup.java b/sonar-server/src/main/java/org/sonar/server/debt/DebtModelBackup.java
index 5ea075a0fc2..4561f6a5c48 100644
--- a/sonar-server/src/main/java/org/sonar/server/debt/DebtModelBackup.java
+++ b/sonar-server/src/main/java/org/sonar/server/debt/DebtModelBackup.java
@@ -157,14 +157,17 @@ public class DebtModelBackup implements ServerComponent {
for (RuleDto rule : ruleDtos) {
// Restore default debt definitions
RulesDefinition.Rule ruleDef = ruleDef(rule, rules);
- String subCharacteristicKey = ruleDef.debtSubCharacteristic();
- CharacteristicDto subCharacteristicDto = characteristicByKey(subCharacteristicKey, allCharacteristicDtos);
- DebtRemediationFunction remediationFunction = ruleDef.debtRemediationFunction();
- boolean hasDebtDefinition = subCharacteristicDto != null && remediationFunction != null;
- rule.setDefaultSubCharacteristicId(hasDebtDefinition ? subCharacteristicDto.getId() : null);
- rule.setDefaultRemediationFunction(hasDebtDefinition ? remediationFunction.type().name() : null);
- rule.setDefaultRemediationCoefficient(hasDebtDefinition ? remediationFunction.coefficient() : null);
- rule.setDefaultRemediationOffset(hasDebtDefinition ? remediationFunction.offset() : null);
+ if (ruleDef != null) {
+ // TODO when can it be null ?
+ String subCharacteristicKey = ruleDef.debtSubCharacteristic();
+ CharacteristicDto subCharacteristicDto = characteristicByKey(subCharacteristicKey, allCharacteristicDtos);
+ DebtRemediationFunction remediationFunction = ruleDef.debtRemediationFunction();
+ boolean hasDebtDefinition = subCharacteristicDto != null && remediationFunction != null;
+ rule.setDefaultSubCharacteristicId(hasDebtDefinition ? subCharacteristicDto.getId() : null);
+ rule.setDefaultRemediationFunction(hasDebtDefinition ? remediationFunction.type().name() : null);
+ rule.setDefaultRemediationCoefficient(hasDebtDefinition ? remediationFunction.coefficient() : null);
+ rule.setDefaultRemediationOffset(hasDebtDefinition ? remediationFunction.offset() : null);
+ }
// Reset overridden debt definitions
rule.setSubCharacteristicId(null);
@@ -347,13 +350,14 @@ public class DebtModelBackup implements ServerComponent {
}, null);
}
+ @CheckForNull
private static RulesDefinition.Rule ruleDef(final RuleDto rule, List<RulesDefinition.Rule> rules) {
return Iterables.find(rules, new Predicate<RulesDefinition.Rule>() {
@Override
public boolean apply(@Nullable RulesDefinition.Rule input) {
return input != null && rule.getRepositoryKey().equals(input.repository().key()) && rule.getRuleKey().equals(input.key());
}
- });
+ }, null);
}
@CheckForNull