nastra commented on code in PR #11609: URL: https://github.com/apache/iceberg/pull/11609#discussion_r1852343390
########## core/src/main/java/org/apache/iceberg/TableMetadataParser.java: ########## @@ -122,15 +122,25 @@ public static void write(TableMetadata metadata, OutputFile outputFile) { public static void internalWrite( TableMetadata metadata, OutputFile outputFile, boolean overwrite) { boolean isGzip = Codec.fromFileName(outputFile.location()) == Codec.GZIP; - try (OutputStream os = overwrite ? outputFile.createOrOverwrite() : outputFile.create(); - OutputStream gos = isGzip ? new GZIPOutputStream(os) : os; + OutputStream os = overwrite ? outputFile.createOrOverwrite() : outputFile.create(); + // if isGzip is true, os will be closed by GZIPOutputStream, + // otherwise, os will be closed by try-with-resources + try (OutputStream gos = isGzip ? new GZIPOutputStream(os) : os; OutputStreamWriter writer = new OutputStreamWriter(gos, StandardCharsets.UTF_8)) { JsonGenerator generator = JsonUtil.factory().createGenerator(writer); generator.useDefaultPrettyPrinter(); toJson(metadata, generator); generator.flush(); } catch (IOException e) { throw new RuntimeIOException(e, "Failed to write json to file: %s", outputFile); + } finally { Review Comment: additionally, whatever fix we do, we should also apply to `ViewMetadataParser` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org For additional commands, e-mail: issues-h...@iceberg.apache.org