From 32fd445dd263250f3afa065059b178d0f352c77b Mon Sep 17 00:00:00 2001 From: Andreas Frohwerk Date: Tue, 13 Nov 2018 22:23:44 +0100 Subject: [PATCH] NO-JIRA Fix minor leak in FileMoveManagerTest Not closing the InputStream makes this test flaky on Windows. The test breaks because FileMoveManager::delete(java.io.File) Line 221 fails to delete the file if it's still "owned" by the JVM process on Windows. --- .../core/server/files/FileMoveManagerTest.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/artemis-server/src/test/java/org/apache/activemq/artemis/core/server/files/FileMoveManagerTest.java b/artemis-server/src/test/java/org/apache/activemq/artemis/core/server/files/FileMoveManagerTest.java index bf8cfb2e58..bb062fcada 100644 --- a/artemis-server/src/test/java/org/apache/activemq/artemis/core/server/files/FileMoveManagerTest.java +++ b/artemis-server/src/test/java/org/apache/activemq/artemis/core/server/files/FileMoveManagerTest.java @@ -352,11 +352,12 @@ public class FileMoveManagerTest { private void checkFile(File bkpFolder, String file) throws IOException { File fileRead = new File(bkpFolder, file); - InputStreamReader stream = new InputStreamReader(new FileInputStream(fileRead)); - BufferedReader reader = new BufferedReader(stream); - String valueRead = reader.readLine(); - int id = Integer.parseInt(file.substring(0, file.indexOf('.'))); - Assert.assertEquals("content of the file wasn't the expected", id, Integer.parseInt(valueRead)); + try (InputStreamReader stream = new InputStreamReader(new FileInputStream(fileRead))) { + BufferedReader reader = new BufferedReader(stream); + String valueRead = reader.readLine(); + int id = Integer.parseInt(file.substring(0, file.indexOf('.'))); + Assert.assertEquals("content of the file wasn't the expected", id, Integer.parseInt(valueRead)); + } } }