diff --git a/src/test/java/org/apache/commons/lang3/event/EventListenerSupportTest.java b/src/test/java/org/apache/commons/lang3/event/EventListenerSupportTest.java index facff22da..937133985 100644 --- a/src/test/java/org/apache/commons/lang3/event/EventListenerSupportTest.java +++ b/src/test/java/org/apache/commons/lang3/event/EventListenerSupportTest.java @@ -142,10 +142,9 @@ public class EventListenerSupportTest { //serialize: final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - final ObjectOutputStream objectOutputStream = new ObjectOutputStream(outputStream); - - objectOutputStream.writeObject(listenerSupport); - objectOutputStream.close(); + try (final ObjectOutputStream objectOutputStream = new ObjectOutputStream(outputStream)) { + objectOutputStream.writeObject(listenerSupport); + } //deserialize: @SuppressWarnings("unchecked")