From: Jean-Baptiste Lievremont Date: Thu, 10 Apr 2014 14:31:17 +0000 (+0200) Subject: Fix quality flaws X-Git-Tag: 4.3~60 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=c06b7b1d24ce232ece2754397f70abeee15b7330;p=sonarqube.git Fix quality flaws --- 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 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) 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"));