From c91175cb97c06c51dc35f3263a4dd4920b2c9b53 Mon Sep 17 00:00:00 2001 From: chrislu Date: Sun, 23 Nov 2025 22:15:12 -0800 Subject: [PATCH] fix: make path variable final for anonymous inner class Java compilation error: - 'local variables referenced from an inner class must be final or effectively final' - The 'path' variable was being reassigned (path = qualify(path)) - This made it non-effectively-final Solution: - Create 'final Path finalPath = path' after qualification - Use finalPath in the anonymous FSDataOutputStream subclass - Applied to both create() and append() methods --- .../java/seaweed/hdfs/SeaweedFileSystem.java | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/other/java/hdfs3/src/main/java/seaweed/hdfs/SeaweedFileSystem.java b/other/java/hdfs3/src/main/java/seaweed/hdfs/SeaweedFileSystem.java index 3bcfbcfca..b8852950b 100644 --- a/other/java/hdfs3/src/main/java/seaweed/hdfs/SeaweedFileSystem.java +++ b/other/java/hdfs3/src/main/java/seaweed/hdfs/SeaweedFileSystem.java @@ -98,6 +98,7 @@ public class SeaweedFileSystem extends FileSystem { LOG.debug("create path: {} bufferSize:{} blockSize:{}", path, bufferSize, blockSize); path = qualify(path); + final Path finalPath = path; // For use in anonymous inner class try { // Priority: 1) non-empty FS_SEAWEED_REPLICATION, 2) empty string -> filer @@ -111,15 +112,17 @@ public class SeaweedFileSystem extends FileSystem { replicaPlacement = String.format("%03d", replication - 1); } int seaweedBufferSize = this.getConf().getInt(FS_SEAWEED_BUFFER_SIZE, FS_SEAWEED_DEFAULT_BUFFER_SIZE); - SeaweedHadoopOutputStream outputStream = (SeaweedHadoopOutputStream) seaweedFileSystemStore.createFile(path, overwrite, permission, + SeaweedHadoopOutputStream outputStream = (SeaweedHadoopOutputStream) seaweedFileSystemStore.createFile(path, + overwrite, permission, seaweedBufferSize, replicaPlacement); // Use custom FSDataOutputStream that delegates getPos() to our stream - LOG.info("[DEBUG-2024] Creating FSDataOutputStream with custom getPos() override for path: {}", path); + LOG.info("[DEBUG-2024] Creating FSDataOutputStream with custom getPos() override for path: {}", finalPath); return new FSDataOutputStream(outputStream, statistics) { @Override public long getPos() { long pos = outputStream.getPos(); - LOG.info("[DEBUG-2024] FSDataOutputStream.getPos() override called! Returning: {} for path: {}", pos, path); + LOG.info("[DEBUG-2024] FSDataOutputStream.getPos() override called! Returning: {} for path: {}", + pos, finalPath); return pos; } }; @@ -162,16 +165,21 @@ public class SeaweedFileSystem extends FileSystem { LOG.debug("append path: {} bufferSize:{}", path, bufferSize); path = qualify(path); + final Path finalPath = path; // For use in anonymous inner class try { int seaweedBufferSize = this.getConf().getInt(FS_SEAWEED_BUFFER_SIZE, FS_SEAWEED_DEFAULT_BUFFER_SIZE); - SeaweedHadoopOutputStream outputStream = (SeaweedHadoopOutputStream) seaweedFileSystemStore.createFile(path, false, null, seaweedBufferSize, ""); + SeaweedHadoopOutputStream outputStream = (SeaweedHadoopOutputStream) seaweedFileSystemStore.createFile(path, + false, null, seaweedBufferSize, ""); // Use custom FSDataOutputStream that delegates getPos() to our stream - LOG.info("[DEBUG-2024] Creating FSDataOutputStream (append) with custom getPos() override for path: {}", path); + LOG.info("[DEBUG-2024] Creating FSDataOutputStream (append) with custom getPos() override for path: {}", + finalPath); return new FSDataOutputStream(outputStream, statistics) { @Override public long getPos() { long pos = outputStream.getPos(); - LOG.info("[DEBUG-2024] FSDataOutputStream.getPos() override called (append)! Returning: {} for path: {}", pos, path); + LOG.info( + "[DEBUG-2024] FSDataOutputStream.getPos() override called (append)! Returning: {} for path: {}", + pos, finalPath); return pos; } };