From 51d4837c19a4fff874e9eda4530dad40e7882cae Mon Sep 17 00:00:00 2001 From: Brendan Le Ny Date: Mon, 24 Jun 2024 15:46:56 +0200 Subject: [PATCH] Close stream --- .../java/sh/libre/scim/core/GroupScimService.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/sh/libre/scim/core/GroupScimService.java b/src/main/java/sh/libre/scim/core/GroupScimService.java index 4245b247c5..e5b2315552 100644 --- a/src/main/java/sh/libre/scim/core/GroupScimService.java +++ b/src/main/java/sh/libre/scim/core/GroupScimService.java @@ -41,10 +41,14 @@ public class GroupScimService extends AbstractScimService { Set names = new TreeSet<>(); resource.getId().ifPresent(names::add); resource.getDisplayName().ifPresent(names::add); - Optional group = getKeycloakDao().getGroupsStream() - .filter(groupModel -> names.contains(groupModel.getName())) - .findFirst(); - return group.map(GroupModel::getId).map(KeycloakId::new); + try (Stream groupsStream = getKeycloakDao().getGroupsStream()) { + Optional group = groupsStream + .filter(groupModel -> names.contains(groupModel.getName())) + .findFirst(); + return group + .map(GroupModel::getId) + .map(KeycloakId::new); + } } @Override