diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/impl/FsVolumeImpl.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/impl/FsVolumeImpl.java index 08564de689..97bb09b9be 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/impl/FsVolumeImpl.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/impl/FsVolumeImpl.java @@ -1132,9 +1132,10 @@ private byte[] loadLastPartialChunkChecksum( int offsetInChecksum = BlockMetadataHeader.getHeaderSize() + (int)(onDiskLen / bytesPerChecksum * checksumSize); byte[] lastChecksum = new byte[checksumSize]; - RandomAccessFile raf = new RandomAccessFile(metaFile, "r"); - raf.seek(offsetInChecksum); - raf.read(lastChecksum, 0, checksumSize); + try (RandomAccessFile raf = new RandomAccessFile(metaFile, "r")) { + raf.seek(offsetInChecksum); + raf.read(lastChecksum, 0, checksumSize); + } return lastChecksum; }