diff options
author | Stephane Gamard <stephane.gamard@searchbox.com> | 2014-07-01 16:06:22 +0200 |
---|---|---|
committer | Stephane Gamard <stephane.gamard@searchbox.com> | 2014-07-01 16:50:32 +0200 |
commit | 3f79488e2b6476d304c362c7e5b1155e5d76f35f (patch) | |
tree | 683de9b00bc1f3aabdbe89af434262028fb1d36d | |
parent | d223c5ded79b36396ad2b4b16dbbe1dd2dc24cd1 (diff) | |
download | sonarqube-3f79488e2b6476d304c362c7e5b1155e5d76f35f.tar.gz sonarqube-3f79488e2b6476d304c362c7e5b1155e5d76f35f.zip |
fix quality flaw (rule.getLanguage() can be null)
-rw-r--r-- | sonar-core/src/main/java/org/sonar/core/rule/RuleDto.java | 8 | ||||
-rw-r--r-- | sonar-server/pom.xml | 2 | ||||
-rw-r--r-- | sonar-server/src/main/java/org/sonar/server/rule/index/RuleNormalizer.java | 27 |
3 files changed, 20 insertions, 17 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/rule/RuleDto.java b/sonar-core/src/main/java/org/sonar/core/rule/RuleDto.java index fd3909bcc58..5b065f8d699 100644 --- a/sonar-core/src/main/java/org/sonar/core/rule/RuleDto.java +++ b/sonar-core/src/main/java/org/sonar/core/rule/RuleDto.java @@ -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; } diff --git a/sonar-server/pom.xml b/sonar-server/pom.xml index f42a71c7e4d..4c72cc20ea6 100644 --- a/sonar-server/pom.xml +++ b/sonar-server/pom.xml @@ -455,7 +455,7 @@ <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> diff --git a/sonar-server/src/main/java/org/sonar/server/rule/index/RuleNormalizer.java b/sonar-server/src/main/java/org/sonar/server/rule/index/RuleNormalizer.java index 32c4eab70a4..beaad6a900c 100644 --- a/sonar-server/src/main/java/org/sonar/server/rule/index/RuleNormalizer.java +++ b/sonar-server/src/main/java/org/sonar/server/rule/index/RuleNormalizer.java @@ -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()); |