]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9441 WS api/organizations/search_my_organizations fails properly when an except... 2186/head
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Tue, 20 Jun 2017 12:26:15 +0000 (14:26 +0200)
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Tue, 20 Jun 2017 13:16:02 +0000 (15:16 +0200)
server/sonar-server/src/main/java/org/sonar/server/organization/ws/SearchMyOrganizationsAction.java

index 5e2946b3081e142c01de1f120b4a8c9a4c319a9d..a1f1835080f2d59844219bb3a56448162e9716f9 100644 (file)
@@ -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();
     }
   }
 }