]> source.dussan.org Git - sonarqube.git/commitdiff
Fix quality flaws
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Fri, 4 Apr 2014 12:51:03 +0000 (14:51 +0200)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Fri, 4 Apr 2014 12:51:03 +0000 (14:51 +0200)
sonar-server/src/main/java/org/sonar/server/debt/DebtModelBackup.java
sonar-server/src/main/java/org/sonar/server/rule/RuleRegistry.java
sonar-server/src/main/java/org/sonar/server/startup/CopyRequirementsFromCharacteristicsToRules.java

index abe57f2dc8054d5eb7ef35157ff5566c49e3dc4c..f4a972e5f3ce0eb3502251fa5b8db66d9356762b 100644 (file)
@@ -25,6 +25,8 @@ import com.google.common.collect.Iterables;
 import org.apache.commons.io.IOUtils;
 import org.apache.commons.lang.ObjectUtils;
 import org.apache.ibatis.session.SqlSession;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.sonar.api.ServerComponent;
 import org.sonar.api.rule.RuleKey;
 import org.sonar.api.server.debt.DebtCharacteristic;
@@ -58,6 +60,8 @@ import static org.sonar.server.debt.DebtModelXMLExporter.RuleDebt;
 
 public class DebtModelBackup implements ServerComponent {
 
+  private static final Logger LOG = LoggerFactory.getLogger(DebtModelBackup.class);
+
   private final MyBatis mybatis;
   private final CharacteristicDao dao;
   private final RuleDao ruleDao;
@@ -213,6 +217,7 @@ public class DebtModelBackup implements ServerComponent {
 
       session.commit();
     } catch (IllegalArgumentException e) {
+      LOG.debug("Error when restoring the model", e);
       validationMessages.addErrorText(e.getMessage());
     } finally {
       MyBatis.closeQuietly(session);
@@ -365,13 +370,16 @@ public class DebtModelBackup implements ServerComponent {
       debtModel.characteristicById(effectiveSubCharacteristicId) : null;
     if (subCharacteristic != null) {
       ruleDebt.setSubCharacteristicKey(subCharacteristic.key());
-      if (rule.getRemediationFunction() != null) {
-        ruleDebt.setFunction(rule.getRemediationFunction());
+
+      String overriddenFunction = rule.getRemediationFunction();
+      String defaultFunction = rule.getDefaultRemediationFunction();
+      if (overriddenFunction != null) {
+        ruleDebt.setFunction(overriddenFunction);
         ruleDebt.setCoefficient(rule.getRemediationCoefficient());
         ruleDebt.setOffset(rule.getRemediationOffset());
         return ruleDebt;
-      } else if (rule.getDefaultRemediationFunction() != null) {
-        ruleDebt.setFunction(rule.getDefaultRemediationFunction());
+      } else if (defaultFunction != null) {
+        ruleDebt.setFunction(defaultFunction);
         ruleDebt.setCoefficient(rule.getDefaultRemediationCoefficient());
         ruleDebt.setOffset(rule.getDefaultRemediationOffset());
         return ruleDebt;
index 6bc01497bd597dd5bb0cfe597849cf8721afdb21..5e32a3cd0bc0e04de812d00dd728494e42909158 100644 (file)
@@ -177,8 +177,9 @@ public class RuleRegistry {
       Integer effectiveSubCharacteristicId = rule.getSubCharacteristicId() != null ? rule.getSubCharacteristicId() : rule.getDefaultSubCharacteristicId();
       CharacteristicDto subCharacteristic = effectiveSubCharacteristicId != null ? characteristicDao.selectById(effectiveSubCharacteristicId, session) : null;
       // The parent id of the sub-characteristic should never be null
-      CharacteristicDto characteristic = (subCharacteristic != null && subCharacteristic.getParentId() != null) ?
-        characteristicDao.selectById(subCharacteristic.getParentId(), session) : null;
+      Integer parentId = subCharacteristic!= null ? subCharacteristic.getParentId() : null;
+      CharacteristicDto characteristic = (subCharacteristic != null && parentId != null) ?
+        characteristicDao.selectById(parentId, session) : null;
       searchIndex.putSynchronous(INDEX_RULES, TYPE_RULE, Long.toString(ruleId), ruleDocument(rule,
         characteristic, subCharacteristic,
         ruleDao.selectParametersByRuleIds(newArrayList(ruleId), session),
index 88aab6ced84e4ce1257489289e5fe51e632a4e50..4f6ea91372ad1356dee458a011532a8578f04e34 100644 (file)
@@ -192,8 +192,8 @@ public class CopyRequirementsFromCharacteristicsToRules {
     private static RequirementDto enabledRequirement(Collection<RequirementDto> requirementsForRule) {
       return Iterables.find(requirementsForRule, new Predicate<RequirementDto>() {
         @Override
-        public boolean apply(RequirementDto input) {
-          return input.isEnabled();
+        public boolean apply(@Nullable RequirementDto input) {
+          return input != null && input.isEnabled();
         }
       }, null);
     }