This is an automated email from the ASF dual-hosted git repository. XiaoHongbo-Hope pushed a commit to branch release-2.1 in repository https://gitbox.apache.org/repos/asf/paimon.git
commit 01dd0daee6950969a6c52b63917d6fe45bfc96cb Author: Arvin <[email protected]> AuthorDate: Fri Sep 11 14:14:33 2026 +0800 [bug] Fix Self-suppression when close rethrows the same exception in FileIO.overwriteFileUtf8 (#9674) (#9679) --- .../src/main/java/org/apache/paimon/fs/FileIO.java | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/paimon-common/src/main/java/org/apache/paimon/fs/FileIO.java b/paimon-common/src/main/java/org/apache/paimon/fs/FileIO.java index 2b0dcec3f7..c20e2c70bb 100644 --- a/paimon-common/src/main/java/org/apache/paimon/fs/FileIO.java +++ b/paimon-common/src/main/java/org/apache/paimon/fs/FileIO.java @@ -378,10 +378,29 @@ public interface FileIO extends Serializable, Closeable { * implementations. */ default void overwriteFileUtf8(Path path, String content) throws IOException { - try (PositionOutputStream out = newOutputStream(path, true)) { + // Some FileIO implementations (e.g. HDFS) rethrow the exact same exception instance from + // close() that was already thrown from write(), which makes the try-with-resources + // suppression mechanism fail with "Self-suppression not permitted". Therefore close the + // stream manually and only add suppressed exceptions that differ from the primary one. + IOException primaryException = null; + PositionOutputStream out = newOutputStream(path, true); + try { OutputStreamWriter writer = new OutputStreamWriter(out, StandardCharsets.UTF_8); writer.write(content); writer.flush(); + } catch (IOException e) { + primaryException = e; + throw e; + } finally { + try { + out.close(); + } catch (IOException closeException) { + if (primaryException == null) { + throw closeException; + } else if (primaryException != closeException) { + primaryException.addSuppressed(closeException); + } + } } }
