From bce9b9e3faa1dda7cbd9ac96d77c8500dda4a350 Mon Sep 17 00:00:00 2001 From: Tony Germano Date: Tue, 23 Dec 2025 19:45:55 -0500 Subject: [PATCH 1/2] Make several private fields final in Client These fields are all either initialized in their declarations or in the constructor and then never reassigned. Signed-off-by: Tony Germano --- server/src/com/mirth/connect/client/core/Client.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/server/src/com/mirth/connect/client/core/Client.java b/server/src/com/mirth/connect/client/core/Client.java index cb4290475..ff080c05d 100644 --- a/server/src/com/mirth/connect/client/core/Client.java +++ b/server/src/com/mirth/connect/client/core/Client.java @@ -135,11 +135,11 @@ public class Client implements UserServletInterface, ConfigurationServletInterfa public static final int MAX_QUERY_PARAM_COLLECTION_SIZE = 100; - private Logger logger = LogManager.getLogger(this.getClass()); - private ServerConnection serverConnection; - private javax.ws.rs.client.Client client; - private URI api; - private AtomicBoolean closed = new AtomicBoolean(false); + private final Logger logger = LogManager.getLogger(this.getClass()); + private final ServerConnection serverConnection; + private final javax.ws.rs.client.Client client; + private final URI api; + private final AtomicBoolean closed = new AtomicBoolean(false); private InvocationHandlerRecorder recorder; /** From 6c2dbfe115131f63ab1a09eefabe0ccac55e9095 Mon Sep 17 00:00:00 2001 From: Tony Germano Date: Tue, 23 Dec 2025 19:50:25 -0500 Subject: [PATCH 2/2] Make Client AutoCloseable and close() idempotent - Make AutoClosable so it can be used in try-with-resources - Removed null check for serverConnection since it cannot be null - Do not shutdown serverConnection or close JAX-RS client if this client is already closed. Signed-off-by: Tony Germano --- server/src/com/mirth/connect/client/core/Client.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/server/src/com/mirth/connect/client/core/Client.java b/server/src/com/mirth/connect/client/core/Client.java index ff080c05d..b9862bd2b 100644 --- a/server/src/com/mirth/connect/client/core/Client.java +++ b/server/src/com/mirth/connect/client/core/Client.java @@ -131,7 +131,11 @@ import com.mirth.connect.util.messagewriter.EncryptionType; import com.mirth.connect.util.messagewriter.MessageWriterOptions; -public class Client implements UserServletInterface, ConfigurationServletInterface, ChannelServletInterface, ChannelGroupServletInterface, ChannelStatusServletInterface, ChannelStatisticsServletInterface, EngineServletInterface, MessageServletInterface, EventServletInterface, AlertServletInterface, CodeTemplateServletInterface, DatabaseTaskServletInterface, UsageServletInterface, ExtensionServletInterface { +public class Client implements UserServletInterface, ConfigurationServletInterface, ChannelServletInterface, + ChannelGroupServletInterface, ChannelStatusServletInterface, ChannelStatisticsServletInterface, + EngineServletInterface, MessageServletInterface, EventServletInterface, AlertServletInterface, + CodeTemplateServletInterface, DatabaseTaskServletInterface, UsageServletInterface, ExtensionServletInterface, + AutoCloseable { public static final int MAX_QUERY_PARAM_COLLECTION_SIZE = 100; @@ -312,9 +316,9 @@ public void setRecorder(InvocationHandlerRecorder recorder) { this.recorder = recorder; } + @Override public void close() { - closed.set(true); - if (serverConnection != null) { + if (!closed.getAndSet(true)) { serverConnection.shutdown(); client.close(); } @@ -2675,4 +2679,4 @@ public void setPluginProperties(String extensionName, Properties properties, boo public String getProperty(String group, String name) throws ClientException { return getServlet(ConfigurationServletInterface.class).getProperty(group, name); } -} \ No newline at end of file +}