From 3a988bb88a5c66f651682083496159a7495e1acb Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Wed, 26 Jul 2017 08:57:52 +0200 Subject: [PATCH] Fix Quality flaws --- .../qualityprofile/RuleActivatorContext.java | 3 ++- .../java/org/sonar/core/util/UtcDateUtils.java | 14 +++++--------- .../main/java/org/sonar/api/config/AesCipher.java | 4 ++-- .../src/main/java/org/sonar/api/utils/Version.java | 2 +- .../scanner/issue/ignore/pattern/LineRange.java | 6 +++--- .../sonar/scanner/issue/tracking/TrackedIssue.java | 4 ++-- 6 files changed, 15 insertions(+), 18 deletions(-) diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/RuleActivatorContext.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/RuleActivatorContext.java index 74c9a8d4a50..9138d494b7f 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/RuleActivatorContext.java +++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/RuleActivatorContext.java @@ -256,6 +256,7 @@ class RuleActivatorContext { void verifyForActivation() { checkRequest(RuleStatus.REMOVED != rule.getStatus(), "Rule was removed: %s", rule.getKey()); checkRequest(!rule.isTemplate(), "Rule template can't be activated on a Quality profile: %s", rule.getKey()); - checkRequest(rulesProfile.getLanguage().equals(rule.getLanguage()), "Rule %s and profile %s have different languages", rule.getKey(), profile != null ? profile.getKee() : rulesProfile.getKee()); + checkRequest(rulesProfile.getLanguage().equals(rule.getLanguage()), + "Rule %s and profile %s have different languages", rule.getKey(), profile != null ? profile.getKee() : rulesProfile.getKee()); } } diff --git a/sonar-core/src/main/java/org/sonar/core/util/UtcDateUtils.java b/sonar-core/src/main/java/org/sonar/core/util/UtcDateUtils.java index d0e8b03fcf5..47998556bbd 100644 --- a/sonar-core/src/main/java/org/sonar/core/util/UtcDateUtils.java +++ b/sonar-core/src/main/java/org/sonar/core/util/UtcDateUtils.java @@ -30,15 +30,11 @@ import org.sonar.api.utils.DateUtils; public class UtcDateUtils { private static final ThreadLocal format = - new ThreadLocal() { - @Override - protected DateFormat initialValue() { - DateFormat f = new SimpleDateFormat(DateUtils.DATETIME_FORMAT); - f.setTimeZone(TimeZone.getTimeZone("UTC")); - return f; - - } - }; + ThreadLocal.withInitial(() -> { + DateFormat f = new SimpleDateFormat(DateUtils.DATETIME_FORMAT); + f.setTimeZone(TimeZone.getTimeZone("UTC")); + return f; + }); private UtcDateUtils() { // only static stuff diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/config/AesCipher.java b/sonar-plugin-api/src/main/java/org/sonar/api/config/AesCipher.java index 049c138dd00..879375b8abc 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/config/AesCipher.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/config/AesCipher.java @@ -59,7 +59,7 @@ final class AesCipher implements Cipher { } catch (RuntimeException e) { throw e; } catch (Exception e) { - throw new RuntimeException(e); + throw new IllegalStateException(e); } } @@ -73,7 +73,7 @@ final class AesCipher implements Cipher { } catch (RuntimeException e) { throw e; } catch (Exception e) { - throw new RuntimeException(e); + throw new IllegalStateException(e); } } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/utils/Version.java b/sonar-plugin-api/src/main/java/org/sonar/api/utils/Version.java index 33a445da069..10029f7483d 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/utils/Version.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/utils/Version.java @@ -218,7 +218,7 @@ public class Version implements Comparable { c = patch - other.patch; if (c == 0) { long diff = buildNumber - other.buildNumber; - c = diff > 0 ? 1 : (diff < 0 ? -1 : 0); + c = (diff > 0) ? 1 : ((diff < 0) ? -1 : 0); } } } diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ignore/pattern/LineRange.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ignore/pattern/LineRange.java index 0f49d446504..19dc312dd8d 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ignore/pattern/LineRange.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ignore/pattern/LineRange.java @@ -65,10 +65,10 @@ public class LineRange { @Override public int hashCode() { - final int prime = 31; + final int PRIME = 31; int result = 1; - result = prime * result + from; - result = prime * result + to; + result = PRIME * result + from; + result = PRIME * result + to; return result; } diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/tracking/TrackedIssue.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/tracking/TrackedIssue.java index b9446d52807..d1b68964093 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/tracking/TrackedIssue.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/tracking/TrackedIssue.java @@ -227,9 +227,9 @@ public class TrackedIssue implements Trackable, Serializable { @Override public int hashCode() { - final int prime = 31; + final int PRIME = 31; int result = 1; - result = prime * result + ((key == null) ? 0 : key.hashCode()); + result = PRIME * result + ((key == null) ? 0 : key.hashCode()); return result; } -- 2.39.5