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 2023/11/26 15:29:51 UTC

(commons-logging) 01/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-logging.git

commit a1c174c086c61f76e993a893eabed8d3c9a71f7c
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Nov 26 10:18:14 2023 -0500

    Use try-with-resources
---
 .../commons/logging/simple/DefaultConfigTestCase.java     | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/src/test/java/org/apache/commons/logging/simple/DefaultConfigTestCase.java b/src/test/java/org/apache/commons/logging/simple/DefaultConfigTestCase.java
index 281edde..2ac9e8a 100644
--- a/src/test/java/org/apache/commons/logging/simple/DefaultConfigTestCase.java
+++ b/src/test/java/org/apache/commons/logging/simple/DefaultConfigTestCase.java
@@ -193,14 +193,13 @@ public class DefaultConfigTestCase extends TestCase {
 
         // Serialize and deserialize the instance
         final ByteArrayOutputStream baos = new ByteArrayOutputStream();
-        final ObjectOutputStream oos = new ObjectOutputStream(baos);
-        oos.writeObject(log);
-        oos.close();
-        final ByteArrayInputStream bais =
-            new ByteArrayInputStream(baos.toByteArray());
-        final ObjectInputStream ois = new ObjectInputStream(bais);
-        log = (Log) ois.readObject();
-        ois.close();
+        try (ObjectOutputStream oos = new ObjectOutputStream(baos)) {
+            oos.writeObject(log);
+        }
+        final ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
+        try (ObjectInputStream ois = new ObjectInputStream(bais)) {
+            log = (Log) ois.readObject();
+        }
 
         // Check the characteristics of the resulting object
         checkStandard();