Skip to content

Apache Lucene open-source search software

#13196, #13213: Fix test on windows to close file so it can be deleted after test run

Uwe Schindler61e5da3fe465
diff --git a/lucene/core/src/test/org/apache/lucene/store/TestMMapDirectory.java b/lucene/core/src/test/org/apache/lucene/store/TestMMapDirectory.java
index edc5d369067..7bec6d5315c 100644
--- a/lucene/core/src/test/org/apache/lucene/store/TestMMapDirectory.java
+++ b/lucene/core/src/test/org/apache/lucene/store/TestMMapDirectory.java
@@ -109,10 +109,11 @@ public class TestMMapDirectory extends BaseDirectoryTestCase {
out.writeBytes(bytes, 0, bytes.length);
}
- final IndexInput in = dir.openInput("test", IOContext.RANDOM);
- final byte[] readBytes = new byte[size];
- in.readBytes(readBytes, 0, readBytes.length);
- assertArrayEquals(bytes, readBytes);
+ try (final IndexInput in = dir.openInput("test", IOContext.RANDOM)) {
+ final byte[] readBytes = new byte[size];
+ in.readBytes(readBytes, 0, readBytes.length);
+ assertArrayEquals(bytes, readBytes);
+ }
}
}
}