]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-10881 Log flooding when a WS param is not an integer as expected
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Tue, 12 Jun 2018 10:52:27 +0000 (12:52 +0200)
committerSonarTech <sonartech@sonarsource.com>
Thu, 14 Jun 2018 09:50:34 +0000 (11:50 +0200)
sonar-plugin-api/src/main/java/org/sonar/api/server/ws/internal/ValidatingRequest.java
sonar-plugin-api/src/test/java/org/sonar/api/server/ws/RequestTest.java
sonar-plugin-api/src/test/java/org/sonar/api/server/ws/internal/SimpleGetRequestTest.java

index 3a97c67b92e96b901a35e87057d8d217115466eb..88f4b6f24bf96d82c8fdebd6d0e77e6e45ea3648 100644 (file)
@@ -216,7 +216,7 @@ public abstract class ValidatingRequest extends Request {
     try {
       return Integer.parseInt(value);
     } catch (NumberFormatException exception) {
-      throw new IllegalStateException(format("'%s' value '%s' cannot be parsed as an integer", key, value), exception);
+      throw new IllegalArgumentException(format("'%s' value '%s' cannot be parsed as an integer", key, value), exception);
     }
   }
 
index d8d9562ce87db772594ba475a981d47fd9a4defd..9dade321f4d44e62618e06af8404d6445249ce0a 100644 (file)
@@ -60,7 +60,7 @@ public class RequestTest {
   @Rule
   public ExpectedException expectedException = ExpectedException.none();
 
-  FakeRequest underTest = new FakeRequest();
+  private FakeRequest underTest = new FakeRequest();
 
   @Before
   public void before() {
@@ -144,6 +144,17 @@ public class RequestTest {
     underTest.setParam(param, "11").param(param);
   }
 
+  @Test
+  public void paramAsInt_throws_IAE_if_maximum_defined_and_value_not_a_number() {
+    String param = "maximum_value_param";
+    defineParameterTestAction(newParam -> newParam.setMaximumValue(10), param);
+
+    expectedException.expect(IllegalArgumentException.class);
+    expectedException.expectMessage("'maximum_value_param' value 'foo' cannot be parsed as an integer");
+
+    underTest.setParam(param, "foo").paramAsInt(param);
+  }
+
   @Test
   public void required_param_as_strings() {
     underTest.setParam("a_required_string", "foo,bar");
@@ -214,7 +225,7 @@ public class RequestTest {
   }
 
   @Test
-  public void param_as_int() {
+  public void paramAsInt() {
     assertThat(underTest.setParam("a_number", "123").paramAsInt("a_number")).isEqualTo(123);
     assertThat(underTest.setParam("a_number", "123").paramAsInt("a_number", 42)).isEqualTo(123);
     assertThat(underTest.setParam("a_number", null).paramAsInt("a_number", 42)).isEqualTo(123);
@@ -609,7 +620,7 @@ public class RequestTest {
   }
 
   @Test
-  public void param_as_part() throws Exception {
+  public void param_as_part() {
     InputStream inputStream = mock(InputStream.class);
     underTest.setPart("key", inputStream, "filename");
 
@@ -621,7 +632,7 @@ public class RequestTest {
   }
 
   @Test
-  public void mandatory_param_as_part() throws Exception {
+  public void mandatory_param_as_part() {
     expectedException.expect(IllegalArgumentException.class);
     expectedException.expectMessage("The 'required_param' parameter is missing");
 
index 3aa51ed7be1d4748691c1f595aa39aabc63d2036..46974bd8201cb5ec40b10e05f01df44efd39fd5d 100644 (file)
@@ -50,7 +50,7 @@ public class SimpleGetRequestTest {
   }
 
   @Test
-  public void get_part() throws Exception {
+  public void get_part() {
     InputStream inputStream = mock(InputStream.class);
     underTest.setPart("key", inputStream, "filename");