From 96672b1c1ab448e71507d1ba983b8a125af2cee7 Mon Sep 17 00:00:00 2001 From: Teryk Bellahsene Date: Tue, 20 Jun 2017 14:26:15 +0200 Subject: [PATCH] SONAR-9441 WS api/organizations/search_my_organizations fails properly when an exception is thrown --- .../ws/SearchMyOrganizationsAction.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) 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(); } } } -- 2.39.5