]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-19478 - Fix java:S1117 Local variable shadowing class fields
authorantoine.vinot <antoine.vinot@sonarsource.com>
Wed, 29 Nov 2023 15:42:52 +0000 (16:42 +0100)
committersonartech <sonartech@sonarsource.com>
Wed, 29 Nov 2023 20:02:37 +0000 (20:02 +0000)
server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/RegisterQualityProfiles.java

index b85d8d84439d66a74d8862ec8817fdd3cde324b0..61481c6cba849cb80475597939bd1945732a35a0 100644 (file)
@@ -32,7 +32,6 @@ import java.util.Locale;
 import java.util.Map;
 import java.util.Set;
 import java.util.function.Function;
-import java.util.stream.Collectors;
 import org.apache.commons.lang.StringUtils;
 import org.sonar.api.Startable;
 import org.sonar.api.resources.Language;
@@ -56,6 +55,7 @@ import org.sonar.server.qualityprofile.builtin.QProfileName;
 
 import static java.lang.String.format;
 import static java.util.stream.Collectors.toMap;
+import static java.util.stream.Collectors.toSet;
 import static org.sonar.server.qualityprofile.ActiveRuleInheritance.NONE;
 
 /**
@@ -180,7 +180,7 @@ public class RegisterQualityProfiles implements Startable {
    * @see <a href="https://jira.sonarsource.com/browse/SONAR-19478">SONAR-19478</a>
    */
   private void ensureBuiltInAreDefaultQPWhenNoRules(DbSession dbSession) {
-    Set<String> activeLanguages = Arrays.stream(languages.all()).map(Language::getKey).collect(Collectors.toSet());
+    Set<String> activeLanguages = Arrays.stream(languages.all()).map(Language::getKey).collect(toSet());
     Map<String, RulesProfileDto> builtInQProfileByLanguage = dbClient.qualityProfileDao().selectBuiltInRuleProfiles(dbSession).stream()
       .collect(toMap(RulesProfileDto::getLanguage, Function.identity(), (oldValue, newValue) -> oldValue));
     List<QProfileDto> defaultProfileWithNoRules = dbClient.qualityProfileDao().selectDefaultProfilesWithoutActiveRules(dbSession, activeLanguages, false);
@@ -237,12 +237,15 @@ public class RegisterQualityProfiles implements Startable {
   }
 
   public void unsetBuiltInFlagAndRenameQPWhenPluginUninstalled(DbSession dbSession) {
-    var pluginsBuiltInQProfiles = builtInQProfileRepository.get()
+    Set<QProfileName> pluginsBuiltInQProfiles = builtInQProfileRepository.get()
       .stream()
       .map(BuiltInQProfile::getQProfileName)
-      .collect(Collectors.toSet());
+      .collect(toSet());
 
-    var languages = pluginsBuiltInQProfiles.stream().map(QProfileName::getLanguage).collect(Collectors.toSet());
+    Set<String> qualityProfileLanguages = pluginsBuiltInQProfiles
+      .stream()
+      .map(QProfileName::getLanguage)
+      .collect(toSet());
 
     dbClient.qualityProfileDao().selectBuiltInRuleProfiles(dbSession)
       .forEach(qProfileDto -> {
@@ -251,7 +254,7 @@ public class RegisterQualityProfiles implements Startable {
         // Built-in Quality Profile can be a leftover from plugin which has been removed
         // Rename Quality Profile and unset built-in flag allowing Quality Profile for existing languages to be removed
         // Quality Profiles for languages not existing anymore are marked as 'REMOVED' and won't be seen in UI
-        if (!pluginsBuiltInQProfiles.contains(dbProfileName) && languages.contains(qProfileDto.getLanguage())) {
+        if (!pluginsBuiltInQProfiles.contains(dbProfileName) && qualityProfileLanguages.contains(qProfileDto.getLanguage())) {
           String oldName = qProfileDto.getName();
           String newName = generateNewProfileName(qProfileDto);
           qProfileDto.setName(newName);