]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5056 Fix issue when reseting debt model and no rule is found
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Wed, 2 Apr 2014 14:45:38 +0000 (16:45 +0200)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Wed, 2 Apr 2014 14:45:38 +0000 (16:45 +0200)
sonar-server/src/main/java/org/sonar/server/debt/DebtModelBackup.java

index 5ea075a0fc2e6192982d44312607acb5e5f6dc89..4561f6a5c48c60da3bbdffd55dd9a4c0de4ec9db 100644 (file)
@@ -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