]> source.dussan.org Git - sonarqube.git/commitdiff
Fix Quality flaws
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Wed, 12 Jul 2017 07:31:54 +0000 (09:31 +0200)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Wed, 12 Jul 2017 09:27:27 +0000 (11:27 +0200)
server/sonar-server/src/main/java/org/sonar/server/project/ws/GhostsAction.java
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/BulkChangeWsResponse.java
server/sonar-server/src/main/java/org/sonar/server/usergroups/ws/UsersAction.java
server/sonar-server/src/main/java/org/sonar/server/ws/ws/ResponseExampleAction.java

index 35a3ded8af7400a327b7b8f70fb234889fa51c74..4605d58e45d67fca18e82cb20f2b9095cef489a6 100644 (file)
@@ -100,10 +100,12 @@ public class GhostsAction implements ProjectsWsAction {
       long nbOfProjects = dbClient.componentDao().countGhostProjects(dbSession, organization.getUuid(), query);
       List<ComponentDto> projects = dbClient.componentDao().selectGhostProjects(dbSession, organization.getUuid(), query,
         searchOptions.getOffset(), searchOptions.getLimit());
-      JsonWriter json = response.newJsonWriter().beginObject();
-      writeProjects(json, projects, desiredFields);
-      searchOptions.writeJson(json, nbOfProjects);
-      json.endObject().close();
+      try (JsonWriter json = response.newJsonWriter()) {
+        json.beginObject();
+        writeProjects(json, projects, desiredFields);
+        searchOptions.writeJson(json, nbOfProjects);
+        json.endObject();
+      }
     }
   }
 
index 066caaed104a0c4c149b9236c8ee66ded923133b..69d6a01966159eac71476061ef17107318ffb6d3 100644 (file)
@@ -31,10 +31,12 @@ class BulkChangeWsResponse {
   }
 
   static void writeResponse(BulkChangeResult result, Response response) {
-    JsonWriter json = response.newJsonWriter().beginObject();
-    json.prop("succeeded", result.countSucceeded());
-    json.prop("failed", result.countFailed());
-    WebServiceEngine.writeErrors(json, result.getErrors());
-    json.endObject().close();
+    try (JsonWriter json = response.newJsonWriter()) {
+      json.beginObject();
+      json.prop("succeeded", result.countSucceeded());
+      json.prop("failed", result.countFailed());
+      WebServiceEngine.writeErrors(json, result.getErrors());
+      json.endObject();
+    }
   }
 }
index c7dc2ffba744fb9d36376f0451effba01b2f2e72..4cc04bd8771b031ea8db3bae9dd4220a2ec93aea 100644 (file)
@@ -92,10 +92,12 @@ public class UsersAction implements UserGroupsWsAction {
       Paging paging = forPageIndex(page).withPageSize(pageSize).andTotal(total);
       List<UserMembershipDto> users = dbClient.groupMembershipDao().selectMembers(dbSession, query, paging.offset(), paging.pageSize());
 
-      JsonWriter json = response.newJsonWriter().beginObject();
-      writeMembers(json, users);
-      writePaging(json, paging);
-      json.endObject().close();
+      try (JsonWriter json = response.newJsonWriter()) {
+        json.beginObject();
+        writeMembers(json, users);
+        writePaging(json, paging);
+        json.endObject();
+      }
     }
   }
 
index 416eb31d8c193d3c90b5645f51d5751d21b87ccc..8e461c7f853a633743203254d4c5cef2f301ed2d 100644 (file)
@@ -22,6 +22,7 @@ package org.sonar.server.ws.ws;
 import org.sonar.api.server.ws.Request;
 import org.sonar.api.server.ws.Response;
 import org.sonar.api.server.ws.WebService;
+import org.sonar.api.utils.text.JsonWriter;
 
 import static com.google.common.base.Preconditions.checkArgument;
 import static com.google.common.base.Preconditions.checkState;
@@ -66,13 +67,12 @@ public class ResponseExampleAction implements WebServicesWsAction {
       return;
     }
 
-    response
-      .newJsonWriter()
-      .beginObject()
-      .prop("format", action.responseExampleFormat())
-      .prop("example", action.responseExampleAsString())
-      .endObject()
-      .close();
+    try (JsonWriter json = response.newJsonWriter()) {
+      json.beginObject()
+        .prop("format", action.responseExampleFormat())
+        .prop("example", action.responseExampleAsString())
+        .endObject();
+    }
   }
 
   @Override