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 1c6c8a81ef93..16a5be6a7f3c 100644 --- a/lucene/core/src/test/org/apache/lucene/store/TestMMapDirectory.java +++ b/lucene/core/src/test/org/apache/lucene/store/TestMMapDirectory.java @@ -134,10 +134,11 @@ public void testWithRandom() throws Exception { 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); + } } } }