Skip to content

Commit 3d85ec2

Browse files
committed
Merge pull request #32610 from alidandach
* pr/32610: Polish "Use try-with-resources when applicable" Use try-with-resources when applicable Closes gh-32610
2 parents 2d40868 + 330dcf1 commit 3d85ec2

File tree

2 files changed

+2
-8
lines changed

2 files changed

+2
-8
lines changed

spring-jms/src/main/java/org/springframework/jms/connection/SingleConnectionFactory.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -575,14 +575,11 @@ protected void closeConnection(Connection con) {
575575
logger.debug("Closing shared JMS Connection: " + con);
576576
}
577577
try {
578-
try {
578+
try (con) {
579579
if (this.startedCount > 0) {
580580
con.stop();
581581
}
582582
}
583-
finally {
584-
con.close();
585-
}
586583
}
587584
catch (jakarta.jms.IllegalStateException ex) {
588585
logger.debug("Ignoring Connection state exception - assuming already closed: " + ex);

spring-jms/src/main/java/org/springframework/jms/support/JmsUtils.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,9 @@ public static void closeConnection(@Nullable Connection con, boolean stop) {
7474
if (con != null) {
7575
try {
7676
if (stop) {
77-
try {
77+
try (con) {
7878
con.stop();
7979
}
80-
finally {
81-
con.close();
82-
}
8380
}
8481
else {
8582
con.close();

0 commit comments

Comments
 (0)