You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2024/08/03 11:41:45 UTC

(commons-dbcp) 03/03: Use try-with-resources

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

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-dbcp.git

commit 5a2f73466e64e410d314db89e858867af8422108
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Aug 3 07:41:05 2024 -0400

    Use try-with-resources
---
 .../commons/dbcp2/datasources/TestPerUserPoolDataSource.java   | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/test/java/org/apache/commons/dbcp2/datasources/TestPerUserPoolDataSource.java b/src/test/java/org/apache/commons/dbcp2/datasources/TestPerUserPoolDataSource.java
index 9cfc774d..d74edc9f 100644
--- a/src/test/java/org/apache/commons/dbcp2/datasources/TestPerUserPoolDataSource.java
+++ b/src/test/java/org/apache/commons/dbcp2/datasources/TestPerUserPoolDataSource.java
@@ -111,11 +111,11 @@ public class TestPerUserPoolDataSource extends TestConnectionPool {
             assertEquals(1, ((PerUserPoolDataSource) ds).getNumIdle(user), "Should be one idle connection in the pool");
             // old password
             assertThrows(SQLException.class, () -> ds.getConnection(user, "bar"), "Should have generated SQLException");
-            final Connection con5 = ds.getConnection(user, "bay"); // take the idle one
-            con3.close(); // Return a connection with the old password
-            ds.getConnection(user, "bay").close(); // will try bad returned connection and destroy it
-            assertEquals(1, ((PerUserPoolDataSource) ds).getNumIdle(user), "Should be one idle connection in the pool");
-            con5.close();
+            try (Connection con5 = ds.getConnection(user, "bay")) { // take the idle one
+                con3.close(); // Return a connection with the old password
+                ds.getConnection(user, "bay").close(); // will try bad returned connection and destroy it
+                assertEquals(1, ((PerUserPoolDataSource) ds).getNumIdle(user), "Should be one idle connection in the pool");
+            }
         } finally {
             TesterDriver.addUser(user, "bar");
         }