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

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


The following commit(s) were added to refs/heads/branch-3.5 by this push:
     new 8fcd9a1b0024 [SPARK-47455][BUILD] Fix resource leak during the 
initialization of `scalaStyleOnCompileConfig` in `SparkBuild.scala`
8fcd9a1b0024 is described below

commit 8fcd9a1b0024d24e3622b1948123e7f239a734a5
Author: yangjie01 <yangji...@baidu.com>
AuthorDate: Wed Mar 20 15:19:33 2024 +0800

    [SPARK-47455][BUILD] Fix resource leak during the initialization of 
`scalaStyleOnCompileConfig` in `SparkBuild.scala`
    
    ### What changes were proposed in this pull request?
    
https://github.com/apache/spark/blob/e01ed0da22f24204fe23143032ff39be7f4b56af/project/SparkBuild.scala#L157-L173
    
    `Source.fromFile(in)` opens a `BufferedSource` resource handle, but it does 
not close it, this pr fix this issue.
    
    ### Why are the changes needed?
    Close resource after used.
    
    ### Does this PR introduce _any_ user-facing change?
    No
    
    ### How was this patch tested?
    Pass GitHub Actions
    
    ### Was this patch authored or co-authored using generative AI tooling?
    No
    
    Closes #45582 from LuciferYang/SPARK-47455.
    
    Authored-by: yangjie01 <yangji...@baidu.com>
    Signed-off-by: yangjie01 <yangji...@baidu.com>
    (cherry picked from commit 85bf7615f85eea3e9192a7684ef711cf44042e05)
    Signed-off-by: yangjie01 <yangji...@baidu.com>
---
 project/SparkBuild.scala | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)

diff --git a/project/SparkBuild.scala b/project/SparkBuild.scala
index 79b58deafde5..dfadfea172d8 100644
--- a/project/SparkBuild.scala
+++ b/project/SparkBuild.scala
@@ -160,16 +160,21 @@ object SparkBuild extends PomBuild {
     val replacements = Map(
       """customId="println" level="error"""" -> """customId="println" 
level="warn""""
     )
-    var contents = Source.fromFile(in).getLines.mkString("\n")
-    for ((k, v) <- replacements) {
-      require(contents.contains(k), s"Could not rewrite '$k' in original 
scalastyle config.")
-      contents = contents.replace(k, v)
-    }
-    new PrintWriter(out) {
-      write(contents)
-      close()
+    val source = Source.fromFile(in)
+    try {
+      var contents = source.getLines.mkString("\n")
+      for ((k, v) <- replacements) {
+        require(contents.contains(k), s"Could not rewrite '$k' in original 
scalastyle config.")
+        contents = contents.replace(k, v)
+      }
+      new PrintWriter(out) {
+        write(contents)
+        close()
+      }
+      out
+    } finally {
+      source.close()
     }
-    out
   }
 
   // Return a cached scalastyle task for a given configuration (usually 
Compile or Test)


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@spark.apache.org
For additional commands, e-mail: commits-h...@spark.apache.org

Reply via email to