From 27e028668b7b0c32435c49bbd29150e22543563d Mon Sep 17 00:00:00 2001 From: Senrian <47714364+Senrian@users.noreply.github.com> Date: Mon, 30 Mar 2026 00:21:32 +0800 Subject: [PATCH] fix: use try-with-resources in DumpCompactionLogCommand to close RandomAccessFile and FileChannel (issue #10218) --- .../tools/command/message/DumpCompactionLogCommand.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/src/main/java/org/apache/rocketmq/tools/command/message/DumpCompactionLogCommand.java b/tools/src/main/java/org/apache/rocketmq/tools/command/message/DumpCompactionLogCommand.java index eee8f3d4bde..3941f5021ce 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/command/message/DumpCompactionLogCommand.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/command/message/DumpCompactionLogCommand.java @@ -69,9 +69,9 @@ public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) throw new SubCommandException("file " + fileName + " is a directory."); } - try { + try (RandomAccessFile raf = new RandomAccessFile(fileName, "rw"); + FileChannel fileChannel = raf.getChannel()) { long fileSize = Files.size(filePath); - FileChannel fileChannel = new RandomAccessFile(fileName, "rw").getChannel(); ByteBuffer buf = fileChannel.map(MapMode.READ_WRITE, 0, fileSize); int current = 0;