]> source.dussan.org Git - sonarqube.git/commitdiff
Fix quality flaws
authorJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Thu, 10 Apr 2014 14:31:17 +0000 (16:31 +0200)
committerJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Thu, 10 Apr 2014 14:31:24 +0000 (16:31 +0200)
sonar-server/src/main/java/org/sonar/server/exceptions/BadRequestException.java
sonar-server/src/main/java/org/sonar/server/rule/ws/AbstractUpdateTagsWsHandler.java
sonar-server/src/test/java/org/sonar/server/rule/ws/AddTagsWsHandlerTest.java

index 90440c312299524fa7f87f8c04ac8854e616ff7a..27e6c2f14530a714841aac1013d79f60c40ca027 100644 (file)
@@ -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);
       }
index 8e48b7e34cf8b7d45cfb7eb6d0332782fc9319a1..50a2b56312bcdc891a27a10d7c8be9884d77c51c 100644 (file)
@@ -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);
index 3195509334f4ea8d60331b44ca070b14bd539889..a6d58d7679908a19886594504ae99060d878a68e 100644 (file)
@@ -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"));