This is an automated email from the ASF dual-hosted git repository.

pan3793 pushed a commit to branch branch-4.0
in repository https://gitbox.apache.org/repos/asf/spark.git


The following commit(s) were added to refs/heads/branch-4.0 by this push:
     new e38d035aba1b [SPARK-56532][CORE] Add `closeQuietly(AutoCloseable)` 
overload to `SparkErrorUtils`
e38d035aba1b is described below

commit e38d035aba1b56489b5e498d95dd045843f8e139
Author: Dongjoon Hyun <[email protected]>
AuthorDate: Fri Apr 17 22:31:49 2026 -0700

    [SPARK-56532][CORE] Add `closeQuietly(AutoCloseable)` overload to 
`SparkErrorUtils`
    
    ### What changes were proposed in this pull request?
    
    This PR adds a new `closeQuietly(AutoCloseable)` overload to 
`SparkErrorUtils`, alongside the existing `closeQuietly(Closeable)`.
    
    **The existing API**
    
https://github.com/apache/spark/blob/0cdbb43624d07fc6ed10586bd20fcb52f39f1685/common/utils/src/main/scala/org/apache/spark/util/SparkErrorUtils.scala#L146
    
    **New API**
    ```scala
    def closeQuietly(closeable: AutoCloseable): Unit
    ```
    
    ### Why are the changes needed?
    
    `Closeable` extends `AutoCloseable`, so the existing helper cannot accept 
resources that implement `AutoCloseable` only. Common examples include JDBC 
types (`Connection`, `Statement`, `ResultSet`), `java.util.stream.Stream`, and 
RocksDB native handles (`Statistics`, `Options`, `ColumnFamilyOptions`, etc.). 
Without this overload, call sites must duplicate the `try { x.close() } catch { 
case _: Exception => }` pattern or cast to `Closeable`. Adding the overload 
removes that boilerplate  [...]
    
    ### Does this PR introduce _any_ user-facing change?
    
    No.
    
    ### How was this patch tested?
    
    Pass the CIs.
    
    ### Was this patch authored or co-authored using generative AI tooling?
    
    Generated-by: Claude Opus 4.7
    
    Closes #55400 from dongjoon-hyun/SPARK-56532.
    
    Authored-by: Dongjoon Hyun <[email protected]>
    Signed-off-by: Dongjoon Hyun <[email protected]>
---
 .../main/scala/org/apache/spark/util/SparkErrorUtils.scala    | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git 
a/common/utils/src/main/scala/org/apache/spark/util/SparkErrorUtils.scala 
b/common/utils/src/main/scala/org/apache/spark/util/SparkErrorUtils.scala
index 872c89e5a29a..dd92ea412bd9 100644
--- a/common/utils/src/main/scala/org/apache/spark/util/SparkErrorUtils.scala
+++ b/common/utils/src/main/scala/org/apache/spark/util/SparkErrorUtils.scala
@@ -105,6 +105,17 @@ private[spark] trait SparkErrorUtils extends Logging {
     }
     new String(out.toByteArray, UTF_8)
   }
+
+  /** Try to close by ignoring all exceptions. */
+  def closeQuietly(closeable: AutoCloseable): Unit = {
+    if (closeable != null) {
+      try {
+        closeable.close()
+      } catch {
+        case _: Exception =>
+      }
+    }
+  }
 }
 
 private[spark] object SparkErrorUtils extends SparkErrorUtils


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to