This is an automated email from the ASF dual-hosted git repository.
JingsongLi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/paimon.git
The following commit(s) were added to refs/heads/master by this push:
new 4bafa12884 [bug] Fix Self-suppression when close rethrows the same
exception in FileIO.overwriteFileUtf8 (#9674) (#9679)
4bafa12884 is described below
commit 4bafa1288448be4fde52b73090b8b384134e89a4
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);
+ }
+ }
}
}