diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/impl/FsDatasetImpl.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/impl/FsDatasetImpl.java index c2efb4d4232..6c48abbebfd 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/impl/FsDatasetImpl.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/impl/FsDatasetImpl.java @@ -1186,9 +1186,10 @@ class FsDatasetImpl implements FsDatasetSpi { 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; }