Browse Source

Add some preconditions to IssueDto

tags/5.2-RC1
Simon Brandhof 8 years ago
parent
commit
362056f315

+ 2
- 2
sonar-core/src/main/java/org/sonar/core/issue/DefaultIssue.java View File

@@ -134,8 +134,8 @@ public class DefaultIssue implements Issue, Trackable, org.sonar.api.ce.measure.
return componentUuid;
}

public DefaultIssue setComponentUuid(@CheckForNull String componentUuid) {
this.componentUuid = componentUuid;
public DefaultIssue setComponentUuid(@Nullable String s) {
this.componentUuid = s;
return this;
}


+ 1
- 1
sonar-core/src/main/java/org/sonar/core/issue/IssueUpdater.java View File

@@ -275,7 +275,7 @@ public class IssueUpdater {
Set<String> newTags = Sets.newHashSet(Collections2.transform(
Collections2.filter(tags, new Predicate<String>() {
@Override
public boolean apply(String tag) {
public boolean apply(@Nullable String tag) {
return tag != null && !tag.isEmpty();
}
}), new Function<String, String>() {

+ 25
- 18
sonar-db/src/main/java/org/sonar/db/issue/IssueDto.java View File

@@ -37,12 +37,13 @@ import org.sonar.api.resources.Project;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.utils.Duration;
import org.sonar.api.utils.KeyValueFormat;
import org.sonar.core.util.Uuids;
import org.sonar.core.issue.DefaultIssue;
import org.sonar.core.util.Uuids;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.protobuf.DbIssues;
import org.sonar.db.rule.RuleDto;

import static com.google.common.base.Preconditions.checkArgument;
import static org.sonar.api.utils.DateUtils.dateToLong;
import static org.sonar.api.utils.DateUtils.longToDate;

@@ -273,6 +274,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);
this.message = s;
return this;
}
@@ -342,6 +344,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);
this.reporter = s;
return this;
}
@@ -352,6 +355,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);
this.assignee = s;
return this;
}
@@ -361,8 +365,9 @@ public final class IssueDto implements Serializable {
return authorLogin;
}

public IssueDto setAuthorLogin(@Nullable String authorLogin) {
this.authorLogin = authorLogin;
public IssueDto setAuthorLogin(@Nullable String s) {
checkArgument(s == null || s.length() <= 255, "Value is too long for column ISSUES.AUTHOR_LOGIN: %s", s);
this.authorLogin = s;
return this;
}

@@ -372,8 +377,7 @@ public final class IssueDto implements Serializable {
}

public IssueDto setIssueAttributes(@Nullable String s) {
Preconditions.checkArgument(s == null || s.length() <= 4000,
"Issue attributes must not exceed 4000 characters: " + s);
checkArgument(s == null || s.length() <= 4000, "Value is too long for column ISSUES.ATTRIBUTES: %s", s);
this.issueAttributes = s;
return this;
}
@@ -518,8 +522,9 @@ public final class IssueDto implements Serializable {
* <p/>
* Please use {@link #setComponent(ComponentDto)} instead
*/
public IssueDto setComponentUuid(@Nullable String componentUuid) {
this.componentUuid = componentUuid;
public IssueDto setComponentUuid(@Nullable String s) {
checkArgument(s == null || s.length() <= 50, "Value is too long for column ISSUES.COMPONENT_UUID: %s", s);
this.componentUuid = s;
return this;
}

@@ -583,8 +588,9 @@ public final class IssueDto implements Serializable {
* <p/>
* Please use {@link #setProject(ComponentDto)} instead
*/
public IssueDto setProjectUuid(@Nullable String projectUuid) {
this.projectUuid = projectUuid;
public IssueDto setProjectUuid(@Nullable String s) {
checkArgument(s == null || s.length() <= 50, "Value is too long for column ISSUES.PROJECT_UUID: %s", s);
this.projectUuid = s;
return this;
}

@@ -632,22 +638,23 @@ public final class IssueDto implements Serializable {
return ImmutableSet.copyOf(TAGS_SPLITTER.split(tags == null ? "" : tags));
}

public IssueDto setTags(Collection<String> tags) {
if (tags.isEmpty()) {
this.tags = null;
public IssueDto setTags(@Nullable Collection<String> tags) {
if (tags == null || tags.isEmpty()) {
setTagsString(null);
} else {
this.tags = TAGS_JOINER.join(tags);
setTagsString(TAGS_JOINER.join(tags));
}
return this;
}

public String getTagsString() {
return tags;
public IssueDto setTagsString(@Nullable String s) {
checkArgument(s == null || s.length() <= 4000, "Value is too long for column ISSUES.TAGS: %s", s);
this.tags = s;
return this;
}

public IssueDto setTagsString(String tags) {
this.tags = tags;
return this;
public String getTagsString() {
return tags;
}

@CheckForNull

+ 1
- 1
sonar-db/src/test/java/org/sonar/db/issue/IssueDtoTest.java View File

@@ -41,7 +41,7 @@ public class IssueDtoTest {
@Test
public void set_data_check_maximal_length() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Issue attributes must not exceed 4000 characters: ");
thrown.expectMessage("Value is too long for column ISSUES.ATTRIBUTES:");

StringBuilder s = new StringBuilder(4500);
for (int i = 0; i < 4500; i++) {

Loading…
Cancel
Save