diff options
author | Léo Geoffroy <leo.geoffroy@sonarsource.com> | 2023-08-17 10:34:57 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2023-08-18 20:02:50 +0000 |
commit | 3d0f9b58b7840d34e183e8ec8a6b5d5edcdac3b0 (patch) | |
tree | 4221ef034d246613daea4caf3479486e35dbf469 /server/sonar-webserver-core | |
parent | 0f6ff74ea84029cad16f78f7ad98293933e1cc1e (diff) | |
download | sonarqube-3d0f9b58b7840d34e183e8ec8a6b5d5edcdac3b0.tar.gz sonarqube-3d0f9b58b7840d34e183e8ec8a6b5d5edcdac3b0.zip |
SONAR-20021 Fix the code smells
Diffstat (limited to 'server/sonar-webserver-core')
3 files changed, 14 insertions, 13 deletions
diff --git a/server/sonar-webserver-core/src/main/java/org/sonar/server/rule/registration/NewRuleCreator.java b/server/sonar-webserver-core/src/main/java/org/sonar/server/rule/registration/NewRuleCreator.java index 5160840ba1f..ac4fe0adf57 100644 --- a/server/sonar-webserver-core/src/main/java/org/sonar/server/rule/registration/NewRuleCreator.java +++ b/server/sonar-webserver-core/src/main/java/org/sonar/server/rule/registration/NewRuleCreator.java @@ -65,6 +65,7 @@ public class NewRuleCreator { } RuleDto createRuleWithSimpleFields(RulesDefinition.Rule ruleDef, String uuid, long now) { + CleanCodeAttribute cleanCodeAttribute = ruleDef.cleanCodeAttribute(); RuleDto ruleDto = new RuleDto() .setUuid(uuid) .setRuleKey(RuleKey.of(ruleDef.repository().key(), ruleDef.key())) @@ -84,7 +85,7 @@ public class NewRuleCreator { .setIsAdHoc(false) .setCreatedAt(now) .setUpdatedAt(now) - .setCleanCodeAttribute(ruleDef.cleanCodeAttribute() != null ? ruleDef.cleanCodeAttribute() : CleanCodeAttribute.defaultCleanCodeAttribute()) + .setCleanCodeAttribute(cleanCodeAttribute != null ? cleanCodeAttribute : CleanCodeAttribute.defaultCleanCodeAttribute()) .setEducationPrinciples(ruleDef.educationPrincipleKeys()); if (isNotEmpty(ruleDef.htmlDescription())) { diff --git a/server/sonar-webserver-core/src/main/java/org/sonar/server/rule/registration/RulesKeyVerifier.java b/server/sonar-webserver-core/src/main/java/org/sonar/server/rule/registration/RulesKeyVerifier.java index 767703fbdb9..5f5d07ab53a 100644 --- a/server/sonar-webserver-core/src/main/java/org/sonar/server/rule/registration/RulesKeyVerifier.java +++ b/server/sonar-webserver-core/src/main/java/org/sonar/server/rule/registration/RulesKeyVerifier.java @@ -25,7 +25,6 @@ import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Set; -import java.util.function.Supplier; import java.util.stream.Collectors; import java.util.stream.Stream; import org.sonar.api.rule.RuleKey; diff --git a/server/sonar-webserver-core/src/main/java/org/sonar/server/rule/registration/StartupRuleUpdater.java b/server/sonar-webserver-core/src/main/java/org/sonar/server/rule/registration/StartupRuleUpdater.java index 6b13dc3b76d..d6332e11e90 100644 --- a/server/sonar-webserver-core/src/main/java/org/sonar/server/rule/registration/StartupRuleUpdater.java +++ b/server/sonar-webserver-core/src/main/java/org/sonar/server/rule/registration/StartupRuleUpdater.java @@ -167,8 +167,9 @@ public class StartupRuleUpdater { private static boolean mergeCleanCodeAttribute(RulesDefinition.Rule def, RuleDto dto) { boolean changed = false; - if (!Objects.equals(dto.getCleanCodeAttribute(), def.cleanCodeAttribute()) && (def.cleanCodeAttribute() != null)) { - dto.setCleanCodeAttribute(def.cleanCodeAttribute()); + CleanCodeAttribute defCleanCodeAttribute = def.cleanCodeAttribute(); + if (!Objects.equals(dto.getCleanCodeAttribute(), defCleanCodeAttribute) && (defCleanCodeAttribute != null)) { + dto.setCleanCodeAttribute(defCleanCodeAttribute); changed = true; } // apply non-nullable default @@ -205,7 +206,7 @@ public class StartupRuleUpdater { private static boolean mergeEducationPrinciples(RulesDefinition.Rule ruleDef, RuleDto dto) { boolean changed = false; if (dto.getEducationPrinciples().size() != ruleDef.educationPrincipleKeys().size() || - !dto.getEducationPrinciples().containsAll(ruleDef.educationPrincipleKeys())) { + !dto.getEducationPrinciples().containsAll(ruleDef.educationPrincipleKeys())) { dto.setEducationPrinciples(ruleDef.educationPrincipleKeys()); changed = true; } @@ -219,10 +220,10 @@ public class StartupRuleUpdater { dto.setSystemTags(emptySet()); changed = true; } else if (dto.getSystemTags().size() != ruleDef.tags().size() || - !dto.getSystemTags().containsAll(ruleDef.tags())) { - dto.setSystemTags(ruleDef.tags()); - changed = true; - } + !dto.getSystemTags().containsAll(ruleDef.tags())) { + dto.setSystemTags(ruleDef.tags()); + changed = true; + } return changed; } @@ -233,10 +234,10 @@ public class StartupRuleUpdater { dto.setSecurityStandards(emptySet()); changed = true; } else if (dto.getSecurityStandards().size() != ruleDef.securityStandards().size() || - !dto.getSecurityStandards().containsAll(ruleDef.securityStandards())) { - dto.setSecurityStandards(ruleDef.securityStandards()); - changed = true; - } + !dto.getSecurityStandards().containsAll(ruleDef.securityStandards())) { + dto.setSecurityStandards(ruleDef.securityStandards()); + changed = true; + } return changed; } |