From 9e8e346e71b304fcf7aeb4e4f4c9a3c7107e1a53 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Wed, 6 Apr 2016 10:23:06 +0200 Subject: [PATCH] Fix quality flaws --- .../process/systeminfo/ProcessStateSystemInfo.java | 2 +- .../org/sonar/server/issue/IssueQueryService.java | 4 +++- .../java/org/sonar/server/issue/IssueUpdater.java | 5 +++-- .../java/org/sonar/server/rule/ws/AppAction.java | 2 +- .../java/org/sonar/server/ws/WebServicesWs.java | 12 +++++------- .../org/sonar/colorizer/KeywordsTokenizer.java | 6 +++--- .../sonar/core/platform/ComponentContainer.java | 3 ++- .../org/sonar/db/qualityprofile/ActiveRuleKey.java | 2 +- .../sonar/db/qualityprofile/QualityProfileDao.java | 3 ++- .../java/org/sonar/api/rules/RulePriority.java | 3 ++- .../src/main/java/org/sonar/api/test/TestCase.java | 3 ++- .../java/org/sonar/test/RunTestsMultipleTimes.java | 14 ++++++++------ 12 files changed, 33 insertions(+), 26 deletions(-) diff --git a/server/sonar-process/src/main/java/org/sonar/process/systeminfo/ProcessStateSystemInfo.java b/server/sonar-process/src/main/java/org/sonar/process/systeminfo/ProcessStateSystemInfo.java index 1ca9297ee33..e0deb9c871c 100644 --- a/server/sonar-process/src/main/java/org/sonar/process/systeminfo/ProcessStateSystemInfo.java +++ b/server/sonar-process/src/main/java/org/sonar/process/systeminfo/ProcessStateSystemInfo.java @@ -57,7 +57,7 @@ public class ProcessStateSystemInfo implements SystemInfoSection { return builder.build(); } - private void addAttributeInMb(ProtobufSystemInfo.Section.Builder builder, String key, long valueInBytes) { + private static void addAttributeInMb(ProtobufSystemInfo.Section.Builder builder, String key, long valueInBytes) { if (valueInBytes >= 0L) { builder.addAttributesBuilder().setKey(key).setLongValue(valueInBytes / MEGABYTE).build(); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/IssueQueryService.java b/server/sonar-server/src/main/java/org/sonar/server/issue/IssueQueryService.java index ee608e26128..b974679fd12 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/IssueQueryService.java +++ b/server/sonar-server/src/main/java/org/sonar/server/issue/IssueQueryService.java @@ -31,6 +31,7 @@ import java.util.Collection; import java.util.Date; import java.util.HashSet; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Set; import javax.annotation.CheckForNull; @@ -160,7 +161,8 @@ public class IssueQueryService { Date actualCreatedAfter = createdAfter; if (createdInLast != null) { - actualCreatedAfter = new DateTime(system.now()).minus(ISOPeriodFormat.standard().parsePeriod("P" + createdInLast.toUpperCase())).toDate(); + actualCreatedAfter = new DateTime(system.now()).minus( + ISOPeriodFormat.standard().parsePeriod("P" + createdInLast.toUpperCase(Locale.ENGLISH))).toDate(); } return actualCreatedAfter; } diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/IssueUpdater.java b/server/sonar-server/src/main/java/org/sonar/server/issue/IssueUpdater.java index 5ad564e61b0..a769c0dc358 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/IssueUpdater.java +++ b/server/sonar-server/src/main/java/org/sonar/server/issue/IssueUpdater.java @@ -28,12 +28,13 @@ import com.google.common.collect.Sets; import java.util.Calendar; import java.util.Collection; import java.util.Date; +import java.util.Locale; import java.util.Set; import javax.annotation.Nullable; import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.time.DateUtils; -import org.sonar.api.rules.RuleType; import org.sonar.api.ce.ComputeEngineSide; +import org.sonar.api.rules.RuleType; import org.sonar.api.server.ServerSide; import org.sonar.api.server.rule.RuleTagFormat; import org.sonar.api.user.User; @@ -318,7 +319,7 @@ public class IssueUpdater { }), new Function() { @Override public String apply(String tag) { - String lowerCaseTag = tag.toLowerCase(); + String lowerCaseTag = tag.toLowerCase(Locale.ENGLISH); RuleTagFormat.validate(lowerCaseTag); return lowerCaseTag; } diff --git a/server/sonar-server/src/main/java/org/sonar/server/rule/ws/AppAction.java b/server/sonar-server/src/main/java/org/sonar/server/rule/ws/AppAction.java index 4a78923cef9..539699d9196 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/rule/ws/AppAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/rule/ws/AppAction.java @@ -125,7 +125,7 @@ public class AppAction implements RulesWsAction { json.name("statuses").beginObject(); for (RuleStatus status : RuleStatus.values()) { if (status != RuleStatus.REMOVED) { - json.prop(status.toString(), i18n.message(Locale.getDefault(), "rules.status." + status.toString().toLowerCase(), status.toString())); + json.prop(status.toString(), i18n.message(Locale.getDefault(), "rules.status." + status.toString().toLowerCase(Locale.ENGLISH), status.toString())); } } json.endObject(); diff --git a/server/sonar-server/src/main/java/org/sonar/server/ws/WebServicesWs.java b/server/sonar-server/src/main/java/org/sonar/server/ws/WebServicesWs.java index 1eaaad67b08..d9715fc9806 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/ws/WebServicesWs.java +++ b/server/sonar-server/src/main/java/org/sonar/server/ws/WebServicesWs.java @@ -21,18 +21,16 @@ package org.sonar.server.ws; import com.google.common.base.Function; import com.google.common.collect.Ordering; +import java.io.IOException; +import java.util.List; +import java.util.Set; +import javax.annotation.Nullable; import org.sonar.api.server.ws.Request; import org.sonar.api.server.ws.RequestHandler; import org.sonar.api.server.ws.Response; import org.sonar.api.server.ws.WebService; import org.sonar.api.utils.text.JsonWriter; -import javax.annotation.Nullable; - -import java.io.IOException; -import java.util.List; -import java.util.Set; - /** * This web service lists all the existing web services, including itself, * for documentation usage. @@ -139,7 +137,7 @@ public class WebServicesWs implements WebService { writer.close(); } - private void writeController(JsonWriter writer, Controller controller, boolean includeInternals) { + private static void writeController(JsonWriter writer, Controller controller, boolean includeInternals) { if (includeInternals || !controller.isInternal()) { writer.beginObject(); writer.prop("path", controller.path()); diff --git a/sonar-colorizer/src/main/java/org/sonar/colorizer/KeywordsTokenizer.java b/sonar-colorizer/src/main/java/org/sonar/colorizer/KeywordsTokenizer.java index 4c68b680f27..2f1192fabeb 100644 --- a/sonar-colorizer/src/main/java/org/sonar/colorizer/KeywordsTokenizer.java +++ b/sonar-colorizer/src/main/java/org/sonar/colorizer/KeywordsTokenizer.java @@ -19,13 +19,13 @@ */ package org.sonar.colorizer; -import org.sonar.channel.CodeReader; - import java.util.Collections; import java.util.HashSet; +import java.util.Locale; import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.sonar.channel.CodeReader; /** * @deprecated since 4.5.2 replace by highlighting mechanism @@ -79,7 +79,7 @@ public class KeywordsTokenizer extends NotThreadSafeTokenizer { private boolean isKeyword(String word) { if (!caseInsensitive && keywords.contains(word)) { return true; - } else if (caseInsensitive && keywords.contains(word.toUpperCase())) { + } else if (caseInsensitive && keywords.contains(word.toUpperCase(Locale.ENGLISH))) { return true; } return false; diff --git a/sonar-core/src/main/java/org/sonar/core/platform/ComponentContainer.java b/sonar-core/src/main/java/org/sonar/core/platform/ComponentContainer.java index 44be61d9266..f94f2245278 100644 --- a/sonar-core/src/main/java/org/sonar/core/platform/ComponentContainer.java +++ b/sonar-core/src/main/java/org/sonar/core/platform/ComponentContainer.java @@ -37,8 +37,8 @@ import org.picocontainer.behaviors.OptInCaching; import org.picocontainer.lifecycle.ReflectionLifecycleStrategy; import org.picocontainer.monitors.NullComponentMonitor; import org.sonar.api.batch.BatchSide; -import org.sonar.api.config.PropertyDefinitions; import org.sonar.api.ce.ComputeEngineSide; +import org.sonar.api.config.PropertyDefinitions; import org.sonar.api.server.ServerSide; import org.sonar.api.utils.log.Loggers; import org.sonar.api.utils.log.Profiler; @@ -276,6 +276,7 @@ public class ComponentContainer implements ContainerPopulator.Container { return pico.getComponent(key); } + @Override public List getComponentsByType(Class tClass) { return pico.getComponents(tClass); } diff --git a/sonar-db/src/main/java/org/sonar/db/qualityprofile/ActiveRuleKey.java b/sonar-db/src/main/java/org/sonar/db/qualityprofile/ActiveRuleKey.java index 3077a4e80a2..46c3d54d5cb 100644 --- a/sonar-db/src/main/java/org/sonar/db/qualityprofile/ActiveRuleKey.java +++ b/sonar-db/src/main/java/org/sonar/db/qualityprofile/ActiveRuleKey.java @@ -52,7 +52,7 @@ public class ActiveRuleKey implements Serializable, Comparable { */ public static ActiveRuleKey parse(String s) { Preconditions.checkArgument(s.split(":").length >= 3, "Bad format of activeRule key: " + s); - int semiColonPos = s.indexOf(":"); + int semiColonPos = s.indexOf(':'); String key = s.substring(0, semiColonPos); String ruleKey = s.substring(semiColonPos + 1); return ActiveRuleKey.of(key, RuleKey.parse(ruleKey)); diff --git a/sonar-db/src/main/java/org/sonar/db/qualityprofile/QualityProfileDao.java b/sonar-db/src/main/java/org/sonar/db/qualityprofile/QualityProfileDao.java index 8429f7f8207..c1caf994393 100644 --- a/sonar-db/src/main/java/org/sonar/db/qualityprofile/QualityProfileDao.java +++ b/sonar-db/src/main/java/org/sonar/db/qualityprofile/QualityProfileDao.java @@ -26,6 +26,7 @@ import com.google.common.collect.Maps; import java.util.Collection; import java.util.Date; import java.util.List; +import java.util.Locale; import java.util.Map; import javax.annotation.CheckForNull; import javax.annotation.Nonnull; @@ -374,7 +375,7 @@ public class QualityProfileDao implements Dao { } private String sqlQueryString(String query) { - return query == null ? "%" : "%" + query.toUpperCase() + "%"; + return query == null ? "%" : "%" + query.toUpperCase(Locale.ENGLISH) + "%"; } private static QualityProfileMapper mapper(DbSession session) { diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/rules/RulePriority.java b/sonar-plugin-api/src/main/java/org/sonar/api/rules/RulePriority.java index 60015b4777d..a96b91364e8 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/rules/RulePriority.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/rules/RulePriority.java @@ -19,6 +19,7 @@ */ package org.sonar.api.rules; +import java.util.Locale; import org.sonar.check.Priority; /** @@ -46,7 +47,7 @@ public enum RulePriority { @Deprecated public static RulePriority valueOfString(String level) { try { - return RulePriority.valueOf(level.toUpperCase()); + return RulePriority.valueOf(level.toUpperCase(Locale.ENGLISH)); } catch (IllegalArgumentException ex) { // backward compatibility diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/test/TestCase.java b/sonar-plugin-api/src/main/java/org/sonar/api/test/TestCase.java index e5c35aa1320..2b6d27b582d 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/test/TestCase.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/test/TestCase.java @@ -19,6 +19,7 @@ */ package org.sonar.api.test; +import java.util.Locale; import javax.annotation.CheckForNull; import javax.annotation.Nullable; @@ -31,7 +32,7 @@ public interface TestCase { OK, FAILURE, ERROR, SKIPPED; public static Status of(@Nullable String s) { - return s == null ? null : valueOf(s.toUpperCase()); + return s == null ? null : valueOf(s.toUpperCase(Locale.ENGLISH)); } } diff --git a/sonar-testing-harness/src/main/java/org/sonar/test/RunTestsMultipleTimes.java b/sonar-testing-harness/src/main/java/org/sonar/test/RunTestsMultipleTimes.java index 97809138b8d..32815bc4363 100644 --- a/sonar-testing-harness/src/main/java/org/sonar/test/RunTestsMultipleTimes.java +++ b/sonar-testing-harness/src/main/java/org/sonar/test/RunTestsMultipleTimes.java @@ -19,14 +19,16 @@ */ package org.sonar.test; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; import org.junit.rules.TestRule; import org.junit.runner.Description; import org.junit.runners.model.Statement; -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.*; - public class RunTestsMultipleTimes implements TestRule { final int threads; final int times; @@ -57,7 +59,7 @@ public class RunTestsMultipleTimes implements TestRule { } catch (RuntimeException e) { throw e; } catch (Throwable e) { - throw new RuntimeException(e); + throw new IllegalStateException(e); } } })); @@ -75,4 +77,4 @@ public class RunTestsMultipleTimes implements TestRule { } }; } -} \ No newline at end of file +} -- 2.39.5