aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-db/src
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2016-12-08 11:01:45 +0100
committerJulien Lancelot <julien.lancelot@sonarsource.com>2016-12-08 14:28:46 +0100
commit8840198643624f2d100cf67c87f5a3fb192c6ec4 (patch)
treedecc0b0c840c617a714e9e1506b5aee94b4616d2 /sonar-db/src
parent637a056d414b8b93ccf82eae0ba3b303fa25675a (diff)
downloadsonarqube-8840198643624f2d100cf67c87f5a3fb192c6ec4.tar.gz
sonarqube-8840198643624f2d100cf67c87f5a3fb192c6ec4.zip
SONAR-8464 Allow events name and category to be null
Diffstat (limited to 'sonar-db/src')
-rw-r--r--sonar-db/src/main/java/org/sonar/db/event/EventDto.java12
-rw-r--r--sonar-db/src/main/java/org/sonar/db/event/EventValidator.java13
-rw-r--r--sonar-db/src/test/java/org/sonar/db/event/EventValidatorTest.java2
3 files changed, 22 insertions, 5 deletions
diff --git a/sonar-db/src/main/java/org/sonar/db/event/EventDto.java b/sonar-db/src/main/java/org/sonar/db/event/EventDto.java
index 58aba3b8fac..2fac8530797 100644
--- a/sonar-db/src/main/java/org/sonar/db/event/EventDto.java
+++ b/sonar-db/src/main/java/org/sonar/db/event/EventDto.java
@@ -79,20 +79,28 @@ public class EventDto {
return this;
}
+ @CheckForNull
public String getName() {
return name;
}
- public EventDto setName(String name) {
+ /**
+ * The name of an event should not be null, but we must accept null values as the DB column is not nullable
+ */
+ public EventDto setName(@Nullable String name) {
this.name = checkEventName(name);
return this;
}
+ @CheckForNull
public String getCategory() {
return category;
}
- public EventDto setCategory(String category) {
+ /**
+ * The category of an event should not be null, but we must accept null values as the DB column is not nullable
+ */
+ public EventDto setCategory(@Nullable String category) {
this.category = checkEventCategory(category);
return this;
}
diff --git a/sonar-db/src/main/java/org/sonar/db/event/EventValidator.java b/sonar-db/src/main/java/org/sonar/db/event/EventValidator.java
index 61d7f0907fc..d69684950db 100644
--- a/sonar-db/src/main/java/org/sonar/db/event/EventValidator.java
+++ b/sonar-db/src/main/java/org/sonar/db/event/EventValidator.java
@@ -34,13 +34,21 @@ public class EventValidator {
// prevent instantiation
}
- public static String checkEventName(String name) {
+ @CheckForNull
+ public static String checkEventName(@Nullable String name) {
+ if (name == null) {
+ return null;
+ }
checkArgument(name.length() <= MAX_NAME_LENGTH, "Event name length (%s) is longer than the maximum authorized (%s). '%s' was provided.",
name.length(), MAX_NAME_LENGTH, name);
return name;
}
- public static String checkEventCategory(String category) {
+ @CheckForNull
+ public static String checkEventCategory(@Nullable String category) {
+ if (category == null) {
+ return null;
+ }
checkArgument(category.length() <= MAX_CATEGORY_LENGTH, "Event category length (%s) is longer than the maximum authorized (%s). '%s' was provided.",
category.length(), MAX_CATEGORY_LENGTH, category);
return category;
@@ -51,7 +59,6 @@ public class EventValidator {
if (description == null) {
return null;
}
-
checkArgument(description.length() <= MAX_DESCRIPTION_LENGTH, "Event description length (%s) is longer than the maximum authorized (%s). '%s' was provided.",
description.length(), MAX_DESCRIPTION_LENGTH, description);
return description;
diff --git a/sonar-db/src/test/java/org/sonar/db/event/EventValidatorTest.java b/sonar-db/src/test/java/org/sonar/db/event/EventValidatorTest.java
index f40b459532d..3b1e341882f 100644
--- a/sonar-db/src/test/java/org/sonar/db/event/EventValidatorTest.java
+++ b/sonar-db/src/test/java/org/sonar/db/event/EventValidatorTest.java
@@ -33,7 +33,9 @@ public class EventValidatorTest {
@Test
public void valid_cases() {
EventValidator.checkEventName(repeat("a", 400));
+ EventValidator.checkEventName(null);
EventValidator.checkEventCategory(repeat("a", 50));
+ EventValidator.checkEventCategory(null);
EventValidator.checkEventDescription(repeat("a", 4000));
EventValidator.checkEventDescription(null);
}