aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-db
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2015-09-28 12:18:31 +0200
committerSimon Brandhof <simon.brandhof@sonarsource.com>2015-09-28 12:18:31 +0200
commitfb9e83a748cf059ce3859b07798fbe8b0cdbffaf (patch)
tree8ca374532158f31ab4b2410da0b9b07683b44763 /sonar-db
parent2905a48db212185cfef6cd1c56253bb5bfb6182c (diff)
downloadsonarqube-fb9e83a748cf059ce3859b07798fbe8b0cdbffaf.tar.gz
sonarqube-fb9e83a748cf059ce3859b07798fbe8b0cdbffaf.zip
Improve validation of fields of CeQueueDto and IssueDto
Diffstat (limited to 'sonar-db')
-rw-r--r--sonar-db/src/main/java/org/sonar/db/ce/CeQueueDto.java10
-rw-r--r--sonar-db/src/main/java/org/sonar/db/issue/IssueDto.java38
-rw-r--r--sonar-db/src/test/java/org/sonar/db/issue/IssueDtoTest.java6
3 files changed, 31 insertions, 23 deletions
diff --git a/sonar-db/src/main/java/org/sonar/db/ce/CeQueueDto.java b/sonar-db/src/main/java/org/sonar/db/ce/CeQueueDto.java
index 559fa6fd64d..3031029c0bd 100644
--- a/sonar-db/src/main/java/org/sonar/db/ce/CeQueueDto.java
+++ b/sonar-db/src/main/java/org/sonar/db/ce/CeQueueDto.java
@@ -45,7 +45,7 @@ public class CeQueueDto {
}
public void setUuid(String s) {
- checkArgument(s.length() <= 40, "Value is too long for column CE_QUEUE.UUID: %s", s);
+ checkArgument(s.length() <= 40, "Value of UUID is too long: %s", s);
this.uuid = s;
}
@@ -55,7 +55,7 @@ public class CeQueueDto {
}
public void setComponentUuid(@Nullable String s) {
- checkArgument(s == null || s.length() <= 40, "Value is too long for column CE_QUEUE.COMPONENT_UUID: %s", s);
+ checkArgument(s == null || s.length() <= 40, "Value of component UUID is too long: %s", s);
this.componentUuid = s;
}
@@ -72,7 +72,7 @@ public class CeQueueDto {
}
public void setTaskType(String s) {
- checkArgument(s.length() <= 15, "Value is too long for column CE_QUEUE.TASK_TYPE: %s", s);
+ checkArgument(s.length() <= 15, "Value of task type is too long: %s", s);
this.taskType = s;
}
@@ -82,7 +82,7 @@ public class CeQueueDto {
}
public void setSubmitterLogin(@Nullable String s) {
- checkArgument(s == null || s.length() <= 255, "Value is too long for column CE_QUEUE.SUBMITTER_LOGIN: %s", s);
+ checkArgument(s == null || s.length() <= 255, "Value of submitter login is too long: %s", s);
this.submitterLogin = s;
}
@@ -126,7 +126,7 @@ public class CeQueueDto {
}
@Override
- public boolean equals(Object o) {
+ public boolean equals(@Nullable Object o) {
if (this == o) {
return true;
}
diff --git a/sonar-db/src/main/java/org/sonar/db/issue/IssueDto.java b/sonar-db/src/main/java/org/sonar/db/issue/IssueDto.java
index defdab3fd63..67a907a6a27 100644
--- a/sonar-db/src/main/java/org/sonar/db/issue/IssueDto.java
+++ b/sonar-db/src/main/java/org/sonar/db/issue/IssueDto.java
@@ -245,6 +245,7 @@ public final class IssueDto implements Serializable {
}
public IssueDto setActionPlanKey(@Nullable String s) {
+ checkArgument(s == null || s.length() <= 50, "Value is too long for issue action plan: %s", s);
this.actionPlanKey = s;
return this;
}
@@ -254,8 +255,9 @@ public final class IssueDto implements Serializable {
return severity;
}
- public IssueDto setSeverity(@Nullable String severity) {
- this.severity = severity;
+ public IssueDto setSeverity(@Nullable String s) {
+ checkArgument(s == null || s.length() <= 10, "Value is too long for issue severity: %s", s);
+ this.severity = s;
return this;
}
@@ -274,7 +276,7 @@ public final class IssueDto implements Serializable {
}
public IssueDto setMessage(@Nullable String s) {
- checkArgument(s == null || s.length() <= 4000, "Value is too long for column ISSUES.MESSAGE: %s", s);
+ checkArgument(s == null || s.length() <= 4000, "Value is too long for issue message: %s", s);
this.message = s;
return this;
}
@@ -284,8 +286,9 @@ public final class IssueDto implements Serializable {
return line;
}
- public IssueDto setLine(@Nullable Integer line) {
- this.line = line;
+ public IssueDto setLine(@Nullable Integer i) {
+ checkArgument(i == null || i >= 0, "Value of issue line must be positive: %d", i);
+ this.line = i;
return this;
}
@@ -295,6 +298,7 @@ public final class IssueDto implements Serializable {
}
public IssueDto setEffortToFix(@Nullable Double d) {
+ checkArgument(d == null || d >= 0, "Value of issue effort to fix must be positive: %d", d);
this.effortToFix = d;
return this;
}
@@ -304,8 +308,9 @@ public final class IssueDto implements Serializable {
return debt;
}
- public IssueDto setDebt(@Nullable Long debt) {
- this.debt = debt;
+ public IssueDto setDebt(@Nullable Long l) {
+ checkArgument(l == null || l >= 0, "Value of issue debt must be positive: %d", l);
+ this.debt = l;
return this;
}
@@ -313,8 +318,9 @@ public final class IssueDto implements Serializable {
return status;
}
- public IssueDto setStatus(@Nullable String status) {
- this.status = status;
+ public IssueDto setStatus(@Nullable String s) {
+ checkArgument(s == null || s.length() <= 20, "Value is too long for issue status: %s", s);
+ this.status = s;
return this;
}
@@ -324,6 +330,7 @@ public final class IssueDto implements Serializable {
}
public IssueDto setResolution(@Nullable String s) {
+ checkArgument(s == null || s.length() <= 20, "Value is too long for issue resolution: %s", s);
this.resolution = s;
return this;
}
@@ -333,8 +340,9 @@ public final class IssueDto implements Serializable {
return checksum;
}
- public IssueDto setChecksum(@Nullable String checksum) {
- this.checksum = checksum;
+ public IssueDto setChecksum(@Nullable String s) {
+ checkArgument(s == null || s.length() <= 1000, "Value is too long for issue checksum: %s", s);
+ this.checksum = s;
return this;
}
@@ -344,7 +352,7 @@ public final class IssueDto implements Serializable {
}
public IssueDto setReporter(@Nullable String s) {
- checkArgument(s == null || s.length() <= 255, "Value is too long for column ISSUES.REPORTER: %s", s);
+ checkArgument(s == null || s.length() <= 255, "Value is too long for issue reporter: %s", s);
this.reporter = s;
return this;
}
@@ -355,7 +363,7 @@ public final class IssueDto implements Serializable {
}
public IssueDto setAssignee(@Nullable String s) {
- checkArgument(s == null || s.length() <= 255, "Value is too long for column ISSUES.ASSIGNEE: %s", s);
+ checkArgument(s == null || s.length() <= 255, "Value is too long for issue assignee: %s", s);
this.assignee = s;
return this;
}
@@ -366,7 +374,7 @@ public final class IssueDto implements Serializable {
}
public IssueDto setAuthorLogin(@Nullable String s) {
- checkArgument(s == null || s.length() <= 255, "Value is too long for column ISSUES.AUTHOR_LOGIN: %s", s);
+ checkArgument(s == null || s.length() <= 255, "Value is too long for issue author login: %s", s);
this.authorLogin = s;
return this;
}
@@ -377,7 +385,7 @@ public final class IssueDto implements Serializable {
}
public IssueDto setIssueAttributes(@Nullable String s) {
- checkArgument(s == null || s.length() <= 4000, "Value is too long for column ISSUES.ATTRIBUTES: %s", s);
+ checkArgument(s == null || s.length() <= 4000, "Value is too long for issue attributes: %s", s);
this.issueAttributes = s;
return this;
}
diff --git a/sonar-db/src/test/java/org/sonar/db/issue/IssueDtoTest.java b/sonar-db/src/test/java/org/sonar/db/issue/IssueDtoTest.java
index 809d02cbc52..ed3a905bf85 100644
--- a/sonar-db/src/test/java/org/sonar/db/issue/IssueDtoTest.java
+++ b/sonar-db/src/test/java/org/sonar/db/issue/IssueDtoTest.java
@@ -36,12 +36,12 @@ import static org.assertj.core.api.Assertions.assertThat;
public class IssueDtoTest {
@Rule
- public ExpectedException thrown = ExpectedException.none();
+ public ExpectedException expectedException = ExpectedException.none();
@Test
public void set_data_check_maximal_length() {
- thrown.expect(IllegalArgumentException.class);
- thrown.expectMessage("Value is too long for column ISSUES.ATTRIBUTES:");
+ expectedException.expect(IllegalArgumentException.class);
+ expectedException.expectMessage("Value is too long for issue attributes:");
StringBuilder s = new StringBuilder(4500);
for (int i = 0; i < 4500; i++) {