]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-8004 WS settings/set fails when property set field with a null value
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Wed, 31 Aug 2016 16:24:12 +0000 (18:24 +0200)
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Thu, 1 Sep 2016 14:01:12 +0000 (16:01 +0200)
server/sonar-server/src/main/java/org/sonar/server/setting/ws/SetAction.java
server/sonar-server/src/test/java/org/sonar/server/setting/ws/SetActionTest.java

index 340bbec29643725e12cdfdfd610e2fb7024a14c2..51a4644933776bb91ba3082753529dd9644ca6c4 100644 (file)
@@ -216,7 +216,10 @@ public class SetAction implements SettingsWsAction {
       .map(oneFieldValues -> readOneFieldValues(oneFieldValues, request.getKey()))
       .flatMap(map -> map.entrySet().stream())
       .peek(entry -> valuesByFieldKeys.put(entry.getKey(), entry.getValue()))
-      .forEach(entry -> checkRequest(fieldKeys.contains(entry.getKey()), "Unknown field key '%s' for setting '%s'", entry.getKey(), request.getKey()));
+      .forEach(entry -> {
+        checkRequest(fieldKeys.contains(entry.getKey()), "Unknown field key '%s' for setting '%s'", entry.getKey(), request.getKey());
+        checkRequest(entry.getValue() != null, "Parameter field '%s' must not be null", entry.getKey());
+      });
 
     checkFieldType(request, definition, valuesByFieldKeys);
   }
index 857ee0bae17ba4e20b88c16652922b38276f943f..ca8d5820e4ef66eea36acf042434f459209f3609 100644 (file)
@@ -544,6 +544,29 @@ public class SetActionTest {
     callForGlobalPropertySet("my.key", newArrayList(GSON.toJson(ImmutableMap.of("field", "notAnInt"))));
   }
 
+  @Test
+  public void fail_when_property_set_has_a_null_field_value() {
+    propertyDefinitions.addComponent(PropertyDefinition
+      .builder("my.key")
+      .name("foo")
+      .description("desc")
+      .category("cat")
+      .subCategory("subCat")
+      .type(PropertyType.PROPERTY_SET)
+      .defaultValue("default")
+      .fields(newArrayList(
+        PropertyFieldDefinition.build("field")
+          .name("Field")
+          .type(PropertyType.STRING)
+          .build()))
+      .build());
+
+    expectedException.expect(BadRequestException.class);
+    expectedException.expectMessage("Parameter field 'field' must not be null");
+
+    callForGlobalPropertySet("my.key", newArrayList("{\"field\": null}"));
+  }
+
   @Test
   public void fail_when_property_set_with_invalid_json() {
     propertyDefinitions.addComponent(PropertyDefinition