From: Teryk Bellahsene Date: Tue, 20 Jun 2017 12:26:15 +0000 (+0200) Subject: SONAR-9441 WS api/organizations/search_my_organizations fails properly when an except... X-Git-Tag: 6.5-M2~111 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=96672b1c1ab448e71507d1ba983b8a125af2cee7;p=sonarqube.git SONAR-9441 WS api/organizations/search_my_organizations fails properly when an exception is thrown --- diff --git a/server/sonar-server/src/main/java/org/sonar/server/organization/ws/SearchMyOrganizationsAction.java b/server/sonar-server/src/main/java/org/sonar/server/organization/ws/SearchMyOrganizationsAction.java index 5e2946b3081..a1f1835080f 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/organization/ws/SearchMyOrganizationsAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/organization/ws/SearchMyOrganizationsAction.java @@ -57,14 +57,15 @@ public class SearchMyOrganizationsAction implements OrganizationsWsAction { return; } - try (DbSession dbSession = dbClient.openSession(false); - JsonWriter jsonWriter = response.newJsonWriter()) { - jsonWriter.beginObject(); - jsonWriter.name("organizations").beginArray(); + try (DbSession dbSession = dbClient.openSession(false)) { + JsonWriter json = response.newJsonWriter(); + json.beginObject(); + json.name("organizations").beginArray(); dbClient.organizationDao().selectByPermission(dbSession, userSession.getUserId(), OrganizationPermission.ADMINISTER.getKey()) - .forEach(dto -> jsonWriter.value(dto.getKey())); - jsonWriter.endArray(); - jsonWriter.endObject(); + .forEach(dto -> json.value(dto.getKey())); + json.endArray(); + json.endObject(); + json.close(); } } }