]> source.dussan.org Git - sonarqube.git/commitdiff
fix quality flaw (rule.getLanguage() can be null)
authorStephane Gamard <stephane.gamard@searchbox.com>
Tue, 1 Jul 2014 14:06:22 +0000 (16:06 +0200)
committerStephane Gamard <stephane.gamard@searchbox.com>
Tue, 1 Jul 2014 14:50:32 +0000 (16:50 +0200)
sonar-core/src/main/java/org/sonar/core/rule/RuleDto.java
sonar-server/pom.xml
sonar-server/src/main/java/org/sonar/server/rule/index/RuleNormalizer.java

index fd3909bcc5851e2c3862592ee2d8ba4a7018a910..5b065f8d699ca6733f0031491aa0914c783ac97f 100644 (file)
@@ -30,8 +30,11 @@ import org.sonar.core.persistence.Dto;
 
 import javax.annotation.CheckForNull;
 import javax.annotation.Nullable;
-
-import java.util.*;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.TreeSet;
 
 public final class RuleDto extends Dto<RuleKey> {
 
@@ -165,6 +168,7 @@ public final class RuleDto extends Dto<RuleKey> {
     return this;
   }
 
+  @CheckForNull
   public String getLanguage() {
     return language;
   }
index f42a71c7e4d323a76d9916d899e4c129214b854d..4c72cc20ea6027b33a689cc986c1a4ae53e6b0b3 100644 (file)
                 <sonar.es.http.host>127.0.0.1</sonar.es.http.host>
                 <sonar.es.http.port>9200</sonar.es.http.port>
                 <sonar.log.console>true</sonar.log.console>
-                <sonar.log.profilingLevel>FULL</sonar.log.profilingLevel>
+                <sonar.log.profilingLevel>BASIC</sonar.log.profilingLevel>
                 <sonar.web.context>/dev</sonar.web.context>
               </systemProperties>
             </configuration>
index 32c4eab70a428b767902436f75f4801201ce944a..beaad6a900c662aa24b8ad948ceba03d739e04a4 100644 (file)
@@ -56,14 +56,14 @@ public class RuleNormalizer extends BaseNormalizer<RuleDto, RuleKey> {
     public static final IndexField DEFAULT_VALUE = add(IndexField.Type.STRING, "defaultValue");
     public static final Set<IndexField> ALL_FIELDS = getAllFields();
 
-    private static Set<IndexField> getAllFields() {
+    private static final Set<IndexField> getAllFields() {
       Set<IndexField> fields = new HashSet<IndexField>();
       for (Field classField : RuleParamField.class.getDeclaredFields()) {
         if (classField.getType().isAssignableFrom(IndexField.class)) {
           try {
             fields.add(IndexField.class.cast(classField.get(null)));
           } catch (IllegalAccessException e) {
-            throw new IllegalStateException("Can not introspect rule index fields", e);
+            throw new IllegalStateException("Could not access Field '" + classField.getName() + "'");
           }
         }
       }
@@ -116,29 +116,29 @@ public class RuleNormalizer extends BaseNormalizer<RuleDto, RuleKey> {
     public static final IndexField PARAMS = addEmbedded("params", RuleParamField.ALL_FIELDS);
 
 
-    public static Set<IndexField> ALL_FIELDS = getAllFields();
+    public static final Set<IndexField> ALL_FIELDS = getAllFields();
 
-    private static Set<IndexField> getAllFields() {
+    private static final Set<IndexField> getAllFields() {
       Set<IndexField> fields = new HashSet<IndexField>();
       for (Field classField : RuleField.class.getDeclaredFields()) {
         if (classField.getType().isAssignableFrom(IndexField.class)) {
           try {
             fields.add(IndexField.class.cast(classField.get(null)));
           } catch (IllegalAccessException e) {
-            e.printStackTrace();
+            throw new IllegalStateException("Could not access Field '" + classField.getName() + "'");
           }
         }
       }
       return fields;
     }
 
-    public static IndexField of(String fieldName) {
+    public static final IndexField of(String fieldName) {
       for (IndexField field : ALL_FIELDS) {
         if (field.field().equals(fieldName)) {
           return field;
         }
       }
-      return null;
+      throw new IllegalStateException("Could not find an IndexField for '" + fieldName + "'");
     }
   }
 
@@ -151,16 +151,17 @@ public class RuleNormalizer extends BaseNormalizer<RuleDto, RuleKey> {
   @Override
   public List<UpdateRequest> normalize(RuleKey key) {
     DbSession dbSession = db.openSession(false);
+    List<UpdateRequest> requests = new ArrayList<UpdateRequest>();
     try {
-      List<UpdateRequest> requests = new ArrayList<UpdateRequest>();
-      requests.addAll(normalize(db.ruleDao().getNullableByKey(dbSession, key)));
+      RuleDto rule = db.ruleDao().getByKey(dbSession, key);
+      requests.addAll(normalize(rule));
       for (RuleParamDto param : db.ruleDao().findRuleParamsByRuleKey(dbSession, key)) {
         requests.addAll(normalizeNested(param, key));
       }
-      return requests;
     } finally {
       dbSession.close();
     }
+    return requests;
   }
 
   @Override
@@ -213,8 +214,7 @@ public class RuleNormalizer extends BaseNormalizer<RuleDto, RuleKey> {
       update.put(RuleField.DEFAULT_CHARACTERISTIC.field(), null);
       update.put(RuleField.DEFAULT_SUB_CHARACTERISTIC.field(), null);
       if (rule.getDefaultSubCharacteristicId() != null) {
-        CharacteristicDto characteristic = null;
-        CharacteristicDto subCharacteristic = null;
+        CharacteristicDto characteristic, subCharacteristic = null;
         subCharacteristic = db.debtCharacteristicDao().selectById(rule.getDefaultSubCharacteristicId(), session);
         if (subCharacteristic != null) {
           characteristic = db.debtCharacteristicDao().selectById(subCharacteristic.getParentId());
@@ -228,8 +228,7 @@ public class RuleNormalizer extends BaseNormalizer<RuleDto, RuleKey> {
           update.put(RuleField.CHARACTERISTIC.field(), DebtCharacteristic.NONE);
           update.put(RuleField.SUB_CHARACTERISTIC.field(), DebtCharacteristic.NONE);
         } else {
-          CharacteristicDto characteristic = null;
-          CharacteristicDto subCharacteristic = null;
+          CharacteristicDto characteristic, subCharacteristic = null;
           subCharacteristic = db.debtCharacteristicDao().selectById(rule.getSubCharacteristicId(), session);
           characteristic = db.debtCharacteristicDao().selectById(subCharacteristic.getParentId());
           update.put(RuleField.CHARACTERISTIC.field(), characteristic.getKey());