]> source.dussan.org Git - sonarqube.git/commitdiff
Fix quality flaws
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Wed, 2 Jul 2014 07:16:53 +0000 (09:16 +0200)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Wed, 2 Jul 2014 07:16:53 +0000 (09:16 +0200)
sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleNormalizer.java
sonar-server/src/main/java/org/sonar/server/rule/index/RuleNormalizer.java

index ce6f8dc6f1bddf942e5e1d8f95cc08e6c28c0c2d..3160acf885458548e4e6880d90573f535aaa16aa 100644 (file)
@@ -37,12 +37,7 @@ import org.sonar.server.search.Indexable;
 import org.sonar.server.search.es.ListUpdate;
 
 import java.lang.reflect.Field;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
 
 public class ActiveRuleNormalizer extends BaseNormalizer<ActiveRuleDto, ActiveRuleKey> {
 
@@ -133,6 +128,9 @@ public class ActiveRuleNormalizer extends BaseNormalizer<ActiveRuleDto, ActiveRu
     try {
       // TODO because DTO uses legacy ID pattern
       QualityProfileDto profile = db.qualityProfileDao().getById(activeRuleDto.getProfileId(), session);
+      if (profile == null) {
+        throw new IllegalStateException("Profile is null : " + activeRuleDto.getProfileId());
+      }
       newRule.put(ActiveRuleField.PROFILE_KEY.field(), profile.getKey());
 
       // TODO this should be generated by RegisterRule and modified in DTO.
@@ -140,7 +138,9 @@ public class ActiveRuleNormalizer extends BaseNormalizer<ActiveRuleDto, ActiveRu
       Integer parentId = activeRuleDto.getParentId();
       if (parentId != null) {
         ActiveRuleDto parentDto = db.activeRuleDao().getById(session, parentId);
-        parentKey = parentDto.getKey().toString();
+        if (parentDto != null) {
+          parentKey = parentDto.getKey().toString();
+        }
       }
       newRule.put(ActiveRuleField.PARENT_KEY.field(), parentKey);
     } finally {
index b96b5c8a16f8f38e58b902a440f9c2db17873daf..fa5e522f43c6ca71d8849cf720bf7777527111e5 100644 (file)
@@ -39,12 +39,7 @@ import org.sonar.server.search.Indexable;
 import org.sonar.server.search.es.ListUpdate;
 
 import java.lang.reflect.Field;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
 
 public class RuleNormalizer extends BaseNormalizer<RuleDto, RuleKey> {
 
@@ -220,20 +215,21 @@ public class RuleNormalizer extends BaseNormalizer<RuleDto, RuleKey> {
       if (defaultSubCharacteristicId != null) {
         CharacteristicDto characteristic, subCharacteristic = null;
         subCharacteristic = db.debtCharacteristicDao().selectById(defaultSubCharacteristicId, session);
-
         if (subCharacteristic != null) {
           Integer characteristicId = subCharacteristic.getParentId();
-          characteristic = db.debtCharacteristicDao().selectById(characteristicId);
-          if (characteristic != null) {
-            update.put(RuleField.DEFAULT_CHARACTERISTIC.field(), characteristic.getKey());
-            update.put(RuleField.DEFAULT_SUB_CHARACTERISTIC.field(), subCharacteristic.getKey());
+          if (characteristicId != null) {
+            characteristic = db.debtCharacteristicDao().selectById(characteristicId);
+            if (characteristic != null) {
+              update.put(RuleField.DEFAULT_CHARACTERISTIC.field(), characteristic.getKey());
+              update.put(RuleField.DEFAULT_SUB_CHARACTERISTIC.field(), subCharacteristic.getKey());
+            }
           }
         }
       }
 
       Integer subCharacteristicId = rule.getSubCharacteristicId();
       if (subCharacteristicId != null) {
-        if (subCharacteristicId == -1) {
+        if (subCharacteristicId.equals(-1)) {
           update.put(RuleField.CHARACTERISTIC.field(), DebtCharacteristic.NONE);
           update.put(RuleField.SUB_CHARACTERISTIC.field(), DebtCharacteristic.NONE);
         } else {