From c067855053a2ed2f28326627ffd0718af3d61817 Mon Sep 17 00:00:00 2001 From: Stephane Gamard Date: Tue, 1 Jul 2014 17:47:31 +0200 Subject: [PATCH] fix quality flaws --- .../server/rule/index/RuleNormalizer.java | 35 ++++++++++++------- .../sonar/server/search/es/ListUpdate.java | 2 +- 2 files changed, 24 insertions(+), 13 deletions(-) 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 beaad6a900c..912cfad380e 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 @@ -200,7 +200,8 @@ public class RuleNormalizer extends BaseNormalizer { Integer templateId = rule.getTemplateId(); if (templateId != null) { RuleDto templateRule = db.ruleDao().getById(session, templateId); - update.put(RuleField.TEMPLATE_KEY.field(), templateRule.getKey().toString()); + RuleKey templateKey = templateRule.getKey(); + update.put(RuleField.TEMPLATE_KEY.field(), templateKey != null ? templateKey.toString() : null); } else { update.put(RuleField.TEMPLATE_KEY.field(), null); } @@ -213,26 +214,36 @@ public class RuleNormalizer extends BaseNormalizer { update.put(RuleField.DEFAULT_CHARACTERISTIC.field(), null); update.put(RuleField.DEFAULT_SUB_CHARACTERISTIC.field(), null); - if (rule.getDefaultSubCharacteristicId() != null) { + + Integer defaultSubCharacteristicId = rule.getDefaultSubCharacteristicId(); + if (defaultSubCharacteristicId != null) { CharacteristicDto characteristic, subCharacteristic = null; - subCharacteristic = db.debtCharacteristicDao().selectById(rule.getDefaultSubCharacteristicId(), session); + subCharacteristic = db.debtCharacteristicDao().selectById(defaultSubCharacteristicId, session); + if (subCharacteristic != null) { - characteristic = db.debtCharacteristicDao().selectById(subCharacteristic.getParentId()); - update.put(RuleField.DEFAULT_CHARACTERISTIC.field(), characteristic.getKey()); - update.put(RuleField.DEFAULT_SUB_CHARACTERISTIC.field(), subCharacteristic.getKey()); + 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 (rule.getSubCharacteristicId() != null) { - if (rule.getSubCharacteristicId() == -1) { + Integer subCharacteristicId = rule.getSubCharacteristicId(); + if (subCharacteristicId != null) { + if (subCharacteristicId == -1) { update.put(RuleField.CHARACTERISTIC.field(), DebtCharacteristic.NONE); update.put(RuleField.SUB_CHARACTERISTIC.field(), DebtCharacteristic.NONE); } else { CharacteristicDto characteristic, subCharacteristic = null; - subCharacteristic = db.debtCharacteristicDao().selectById(rule.getSubCharacteristicId(), session); - characteristic = db.debtCharacteristicDao().selectById(subCharacteristic.getParentId()); - update.put(RuleField.CHARACTERISTIC.field(), characteristic.getKey()); - update.put(RuleField.SUB_CHARACTERISTIC.field(), subCharacteristic.getKey()); + subCharacteristic = db.debtCharacteristicDao().selectById(subCharacteristicId, session); + Integer characteristicId = subCharacteristic.getParentId(); + characteristic = db.debtCharacteristicDao().selectById(characteristicId); + if (characteristic != null) { + update.put(RuleField.CHARACTERISTIC.field(), characteristic.getKey()); + update.put(RuleField.SUB_CHARACTERISTIC.field(), subCharacteristic.getKey()); + } } } else { update.put(RuleField.CHARACTERISTIC.field(), null); diff --git a/sonar-server/src/main/java/org/sonar/server/search/es/ListUpdate.java b/sonar-server/src/main/java/org/sonar/server/search/es/ListUpdate.java index 05da420c724..6de0df6a978 100644 --- a/sonar-server/src/main/java/org/sonar/server/search/es/ListUpdate.java +++ b/sonar-server/src/main/java/org/sonar/server/search/es/ListUpdate.java @@ -119,7 +119,7 @@ public class ListUpdate extends AbstractExecutableScript { } } else { // 3. field is a list - Collection items = ((Collection) fieldValue); + Collection items = (Collection) fieldValue; Object target = null; for (Object item : items) { Map fields = (Map) item; -- 2.39.5