vinothchandar commented on code in PR #12536:
URL: https://github.com/apache/hudi/pull/12536#discussion_r1964709911


##########
hudi-io/src/main/java/org/apache/hudi/storage/HoodieStorage.java:
##########
@@ -329,58 +328,48 @@ public final void createImmutableFileInPath(StoragePath 
path,
   public final void createImmutableFileInPath(StoragePath path,
                                               Option<HoodieInstantWriter> 
contentWriter,
                                               boolean needTempFile) throws 
HoodieIOException {
-    OutputStream fsout = null;
-    StoragePath tmpPath = null;
-
-    try {
-      if (!contentWriter.isPresent()) {
-        fsout = create(path, false);
-      }
-
-      if (contentWriter.isPresent() && needTempFile) {
-        StoragePath parent = path.getParent();
-        tmpPath = new StoragePath(parent, path.getName() + "." + 
UUID.randomUUID());
-        fsout = create(tmpPath, false);
-        contentWriter.get().writeToStream(fsout);
-      }
+    boolean usedTmpPath = false;
+    final StoragePath createPath;
+    if (contentWriter.isPresent() && needTempFile) {
+      StoragePath parent = path.getParent();
+      createPath = new StoragePath(parent, path.getName() + "." + 
UUID.randomUUID());
+      usedTmpPath = true;
+    } else {
+      createPath = path;
+    }
 
-      if (contentWriter.isPresent() && !needTempFile) {
-        fsout = create(path, false);
-        contentWriter.get().writeToStream(fsout);
+    try (OutputStream outputStream = create(createPath, false)) {
+      if (contentWriter.isPresent()) {
+        contentWriter.get().writeToStream(outputStream);
       }
     } catch (IOException e) {
-      String errorMsg = "Failed to create file " + (tmpPath != null ? tmpPath 
: path);
+      String errorMsg = "Failed to create/write file " + createPath;
       throw new HoodieIOException(errorMsg, e);
-    } finally {
-      try {
-        if (null != fsout) {
-          fsout.close();
-        }
-      } catch (IOException e) {
-        String errorMsg = "Failed to close file " + (needTempFile ? tmpPath : 
path);
-        throw new HoodieIOException(errorMsg, e);
-      }
+    }
 
+    // do some renaming and cleanup if we used a temp file
+    if (usedTmpPath) {

Review Comment:
   this change is basically trying to avoid try-catch within finally



-- 
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: commits-unsubscr...@hudi.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to