From db3de0d933b19819d60cc73a8730e9944ac32395 Mon Sep 17 00:00:00 2001 From: Brendan Le Ny Date: Mon, 17 Jun 2024 10:34:45 +0200 Subject: [PATCH] Use try with resource --- src/main/java/sh/libre/scim/core/ScimClient.java | 3 ++- src/main/java/sh/libre/scim/core/ScimDispatcher.java | 5 +---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/main/java/sh/libre/scim/core/ScimClient.java b/src/main/java/sh/libre/scim/core/ScimClient.java index 4782b1e079..5831bf3d8c 100644 --- a/src/main/java/sh/libre/scim/core/ScimClient.java +++ b/src/main/java/sh/libre/scim/core/ScimClient.java @@ -28,7 +28,7 @@ import java.util.HashMap; import java.util.Map; -public class ScimClient { +public class ScimClient implements AutoCloseable { private static final Logger LOGGER = Logger.getLogger(ScimClient.class); @@ -299,6 +299,7 @@ public class ScimClient { } } + @Override public void close() { scimRequestBuilder.close(); } diff --git a/src/main/java/sh/libre/scim/core/ScimDispatcher.java b/src/main/java/sh/libre/scim/core/ScimDispatcher.java index bf7757d7c1..df4e220a3d 100644 --- a/src/main/java/sh/libre/scim/core/ScimDispatcher.java +++ b/src/main/java/sh/libre/scim/core/ScimDispatcher.java @@ -33,13 +33,10 @@ public class ScimDispatcher { public void runOne(ComponentModel m, Consumer f) { LOGGER.infof("%s %s %s %s", m.getId(), m.getName(), m.getProviderId(), m.getProviderType()); - ScimClient client = ScimClient.newScimClient(m, session); - try { + try (ScimClient client = ScimClient.newScimClient(m, session)) { f.accept(client); } catch (Exception e) { LOGGER.error(e); - } finally { - client.close(); } } }