This is an automated email from the ASF dual-hosted git repository.

cshannon pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/activemq.git


The following commit(s) were added to refs/heads/main by this push:
     new 27320e4085 AMQ-9723 implemented try with resources for socket (#1449)
27320e4085 is described below

commit 27320e4085424a9b4d43e25b2634c11524591766
Author: Dmitry Kryukov <[email protected]>
AuthorDate: Fri Jun 6 01:28:59 2025 +0300

    AMQ-9723 implemented try with resources for socket (#1449)
---
 .../org/apache/activemq/transport/tcp/QualityOfServiceUtils.java   | 7 +++++--
 .../apache/activemq/transport/tcp/QualityOfServiceUtilsTest.java   | 6 +++---
 2 files changed, 8 insertions(+), 5 deletions(-)

diff --git 
a/activemq-client/src/main/java/org/apache/activemq/transport/tcp/QualityOfServiceUtils.java
 
b/activemq-client/src/main/java/org/apache/activemq/transport/tcp/QualityOfServiceUtils.java
index 5ce83bb2d2..77d91106e1 100644
--- 
a/activemq-client/src/main/java/org/apache/activemq/transport/tcp/QualityOfServiceUtils.java
+++ 
b/activemq-client/src/main/java/org/apache/activemq/transport/tcp/QualityOfServiceUtils.java
@@ -16,6 +16,8 @@
  */
 package org.apache.activemq.transport.tcp;
 
+import java.io.IOException;
+import java.io.UncheckedIOException;
 import java.net.Socket;
 import java.net.SocketException;
 import java.util.HashMap;
@@ -125,8 +127,7 @@ public class QualityOfServiceUtils {
         // The only way to see if there are any values set for the ECN is to
         // read the traffic class automatically set by the system and isolate
         // the ECN bits.
-        Socket socket = new Socket();
-        try {
+        try (Socket socket = new Socket()) {
             int systemTrafficClass = socket.getTrafficClass();
             // The 1st and 2nd bits of the system traffic class are the ECN
             // bits.
@@ -134,6 +135,8 @@ public class QualityOfServiceUtils {
         } catch (SocketException e) {
             throw new IllegalArgumentException("Setting Differentiated 
Services"
                 + " not supported: " + e);
+        } catch (IOException e) {
+            throw new UncheckedIOException(e);
         }
     }
 }
diff --git 
a/activemq-unit-tests/src/test/java/org/apache/activemq/transport/tcp/QualityOfServiceUtilsTest.java
 
b/activemq-unit-tests/src/test/java/org/apache/activemq/transport/tcp/QualityOfServiceUtilsTest.java
index ec619a0fb4..9e229d2aa2 100644
--- 
a/activemq-unit-tests/src/test/java/org/apache/activemq/transport/tcp/QualityOfServiceUtilsTest.java
+++ 
b/activemq-unit-tests/src/test/java/org/apache/activemq/transport/tcp/QualityOfServiceUtilsTest.java
@@ -32,9 +32,9 @@ public class QualityOfServiceUtilsTest extends TestCase {
 
     @Override
     protected void setUp() throws Exception {
-        Socket socket = new Socket();
-        ECN = socket.getTrafficClass() & Integer.parseInt("00000011", 2);
-        socket.close();
+        try (Socket socket = new Socket()) {
+            ECN = socket.getTrafficClass() & Integer.parseInt("00000011", 2);
+        }
     }
 
     @Override


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information, visit: https://activemq.apache.org/contact


Reply via email to