diff options
author | Jean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com> | 2014-04-10 16:31:17 +0200 |
---|---|---|
committer | Jean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com> | 2014-04-10 16:31:24 +0200 |
commit | c06b7b1d24ce232ece2754397f70abeee15b7330 (patch) | |
tree | ba621a790e35c932f1088228bbd6eaa50e856e7d | |
parent | f3c05216665b746045ed50406350615136abd71b (diff) | |
download | sonarqube-c06b7b1d24ce232ece2754397f70abeee15b7330.tar.gz sonarqube-c06b7b1d24ce232ece2754397f70abeee15b7330.zip |
Fix quality flaws
3 files changed, 15 insertions, 3 deletions
diff --git a/sonar-server/src/main/java/org/sonar/server/exceptions/BadRequestException.java b/sonar-server/src/main/java/org/sonar/server/exceptions/BadRequestException.java index 90440c31229..27e6c2f1453 100644 --- a/sonar-server/src/main/java/org/sonar/server/exceptions/BadRequestException.java +++ b/sonar-server/src/main/java/org/sonar/server/exceptions/BadRequestException.java @@ -114,10 +114,9 @@ public class BadRequestException extends ServerException { return l10nKey; } - @CheckForNull public Object[] l10nParams() { if (l10nParams == null) { - return null; + return new Object[0]; } else { return Arrays.copyOf(l10nParams, l10nParams.length); } diff --git a/sonar-server/src/main/java/org/sonar/server/rule/ws/AbstractUpdateTagsWsHandler.java b/sonar-server/src/main/java/org/sonar/server/rule/ws/AbstractUpdateTagsWsHandler.java index 8e48b7e34cf..50a2b56312b 100644 --- a/sonar-server/src/main/java/org/sonar/server/rule/ws/AbstractUpdateTagsWsHandler.java +++ b/sonar-server/src/main/java/org/sonar/server/rule/ws/AbstractUpdateTagsWsHandler.java @@ -19,6 +19,8 @@ */ package org.sonar.server.rule.ws; +import org.sonar.server.exceptions.NotFoundException; + import com.google.common.collect.Sets; import org.elasticsearch.common.collect.Lists; import org.sonar.api.rule.RuleKey; @@ -40,7 +42,11 @@ public abstract class AbstractUpdateTagsWsHandler implements RequestHandler { @Override public void handle(Request request, Response response) { - Rule rule = rules.findByKey(RuleKey.parse(request.mandatoryParam("key"))); + RuleKey ruleKey = RuleKey.parse(request.mandatoryParam("key")); + Rule rule = rules.findByKey(ruleKey); + if (rule == null) { + throw new NotFoundException("No rule found for key " + ruleKey); + } Set<String> allAdminTags = Sets.newHashSet(rule.adminTags()); String[] tagsFromRequest = request.mandatoryParam("tags").split(","); updateTags(allAdminTags, tagsFromRequest); diff --git a/sonar-server/src/test/java/org/sonar/server/rule/ws/AddTagsWsHandlerTest.java b/sonar-server/src/test/java/org/sonar/server/rule/ws/AddTagsWsHandlerTest.java index 3195509334f..a6d58d76799 100644 --- a/sonar-server/src/test/java/org/sonar/server/rule/ws/AddTagsWsHandlerTest.java +++ b/sonar-server/src/test/java/org/sonar/server/rule/ws/AddTagsWsHandlerTest.java @@ -20,6 +20,8 @@ package org.sonar.server.rule.ws; +import org.sonar.server.exceptions.NotFoundException; + import com.google.common.collect.ImmutableList; import org.junit.Before; import org.junit.Test; @@ -72,6 +74,11 @@ public class AddTagsWsHandlerTest { assertThat((List<String>) newTags).hasSize(4).containsOnly("admin1", "admin2", "tag1", "tag2"); } + @Test(expected = NotFoundException.class) + public void add_tags_key_not_found() throws Exception { + tester.newRequest("add_tags").setParam("key", "polop:palap").setParam("tags", "tag1,tag2").execute(); + } + private Rule create(String repoKey, String key, String name, String description) { Rule mockRule = mock(Rule.class); when(mockRule.adminTags()).thenReturn(ImmutableList.of("admin1", "admin2")); |