diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2017-07-12 09:31:54 +0200 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@sonarsource.com> | 2017-07-12 11:27:27 +0200 |
commit | 289be70bf6056b5f3c66a797ecab019891e731d6 (patch) | |
tree | fc7798b1aab7b05f5e326ce0071765e4e35a81a6 /server | |
parent | 8c82a4c246dc8928470ebe0a148725c7f1bd5dcd (diff) | |
download | sonarqube-289be70bf6056b5f3c66a797ecab019891e731d6.tar.gz sonarqube-289be70bf6056b5f3c66a797ecab019891e731d6.zip |
Fix Quality flaws
Diffstat (limited to 'server')
4 files changed, 26 insertions, 20 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/project/ws/GhostsAction.java b/server/sonar-server/src/main/java/org/sonar/server/project/ws/GhostsAction.java index 35a3ded8af7..4605d58e45d 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/project/ws/GhostsAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/project/ws/GhostsAction.java @@ -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(); + } } } diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/BulkChangeWsResponse.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/BulkChangeWsResponse.java index 066caaed104..69d6a019661 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/BulkChangeWsResponse.java +++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/BulkChangeWsResponse.java @@ -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(); + } } } diff --git a/server/sonar-server/src/main/java/org/sonar/server/usergroups/ws/UsersAction.java b/server/sonar-server/src/main/java/org/sonar/server/usergroups/ws/UsersAction.java index c7dc2ffba74..4cc04bd8771 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/usergroups/ws/UsersAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/usergroups/ws/UsersAction.java @@ -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(); + } } } diff --git a/server/sonar-server/src/main/java/org/sonar/server/ws/ws/ResponseExampleAction.java b/server/sonar-server/src/main/java/org/sonar/server/ws/ws/ResponseExampleAction.java index 416eb31d8c1..8e461c7f853 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/ws/ws/ResponseExampleAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/ws/ws/ResponseExampleAction.java @@ -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 |