From 67e2a0659d60ff3825b6119539c0344f5ac80be7 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Tue, 21 Oct 2014 22:37:10 +0200 Subject: [PATCH] SONAR-5758 fix quality flaws --- .../migrations/v451/DeleteUnescapedActivities.java | 14 +++++++++----- .../v451/DeleteUnescapedActivitiesTest.java | 4 ++++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v451/DeleteUnescapedActivities.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v451/DeleteUnescapedActivities.java index 5f9866de881..c0bbe4fa71a 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v451/DeleteUnescapedActivities.java +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v451/DeleteUnescapedActivities.java @@ -26,6 +26,8 @@ import org.sonar.server.db.migrations.MassUpdate; import org.sonar.server.db.migrations.Select; import org.sonar.server.db.migrations.SqlStatement; +import javax.annotation.Nullable; + import java.sql.SQLException; /** @@ -57,11 +59,13 @@ public class DeleteUnescapedActivities extends BaseDataChange { }); } - static boolean isUnescaped(String csv) { - String[] splits = csv.split(";"); - for (String split : splits) { - if (StringUtils.countMatches(split, "=") != 1) { - return true; + static boolean isUnescaped(@Nullable String csv) { + if (csv != null) { + String[] splits = StringUtils.split(csv, ';'); + for (String split : splits) { + if (StringUtils.countMatches(split, "=") != 1) { + return true; + } } } return false; diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v451/DeleteUnescapedActivitiesTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v451/DeleteUnescapedActivitiesTest.java index 4f342cfe5a8..cb13eb73884 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v451/DeleteUnescapedActivitiesTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v451/DeleteUnescapedActivitiesTest.java @@ -47,7 +47,11 @@ public class DeleteUnescapedActivitiesTest { "ruleKey=findbugs:PT_RELATIVE_PATH_TRAVERSAL;profileKey=java-findbugs-74105;severity=MAJOR;" + "key=java-findbugs-74105:findbugs:PT_RELATIVE_PATH_TRAVERSAL")) .isFalse(); + assertThat(DeleteUnescapedActivities.isUnescaped(null)).isFalse(); + assertThat(DeleteUnescapedActivities.isUnescaped("")).isFalse(); + assertThat(DeleteUnescapedActivities.isUnescaped("foo=bar")).isFalse(); assertThat(DeleteUnescapedActivities.isUnescaped("param_xpath=/foo/bar")).isFalse(); + assertThat(DeleteUnescapedActivities.isUnescaped("param_xpath=/foo/bar;foo;ruleKey=S001")).isTrue(); assertThat(DeleteUnescapedActivities.isUnescaped("param_xpath=/foo=foo;ruleKey=S001")).isTrue(); -- 2.39.5