From 62f75d8e9412351314e87fcda4491a1ceb2851b6 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Sat, 2 Dec 2023 09:21:05 -0500 Subject: [PATCH] Use try-with-resources --- .../validator/routines/AbstractNumberValidatorTest.java | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/test/java/org/apache/commons/validator/routines/AbstractNumberValidatorTest.java b/src/test/java/org/apache/commons/validator/routines/AbstractNumberValidatorTest.java index 8b1470cbc..a9847cf84 100644 --- a/src/test/java/org/apache/commons/validator/routines/AbstractNumberValidatorTest.java +++ b/src/test/java/org/apache/commons/validator/routines/AbstractNumberValidatorTest.java @@ -165,22 +165,18 @@ public void testRangeMinMax() { public void testSerialization() { // Serialize the check digit routine final ByteArrayOutputStream baos = new ByteArrayOutputStream(); - try { - final ObjectOutputStream oos = new ObjectOutputStream(baos); + try (ObjectOutputStream oos = new ObjectOutputStream(baos)) { oos.writeObject(validator); oos.flush(); - oos.close(); } catch (final Exception e) { fail(validator.getClass().getName() + " error during serialization: " + e); } // Deserialize the test object Object result = null; - try { - final ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); + try (ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray())) { final ObjectInputStream ois = new ObjectInputStream(bais); result = ois.readObject(); - bais.close(); } catch (final Exception e) { fail(validator.getClass().getName() + " error during deserialization: " + e); }