Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SPARK-47455][BUILD] Fix resource leak during the initialization of scalaStyleOnCompileConfig in SparkBuild.scala #45582

Closed
wants to merge 2 commits into from

Conversation

LuciferYang
Copy link
Contributor

@LuciferYang LuciferYang commented Mar 19, 2024

What changes were proposed in this pull request?

val scalaStyleOnCompileConfig: String = {
val in = "scalastyle-config.xml"
val out = "scalastyle-on-compile.generated.xml"
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()
}
out
}

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

@github-actions github-actions bot added the BUILD label Mar 19, 2024
@LuciferYang LuciferYang changed the title [SPARK-47455][INFRA] Fix Resource Handling of scalaStyleOnCompileConfig in SparkBuild.scala [SPARK-47455][BUILD] Fix Resource Handling of scalaStyleOnCompileConfig in SparkBuild.scala Mar 19, 2024
@LuciferYang LuciferYang marked this pull request as draft March 19, 2024 03:41
@LuciferYang

This comment was marked as outdated.

@LuciferYang LuciferYang changed the title [SPARK-47455][BUILD] Fix Resource Handling of scalaStyleOnCompileConfig in SparkBuild.scala [SPARK-47455][BUILD] Fix resource leak during the initialization of scalaStyleOnCompileConfig in SparkBuild.scala Mar 19, 2024
Copy link
Member

@dongjoon-hyun dongjoon-hyun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1, LGTM.

@LuciferYang LuciferYang marked this pull request as ready for review March 20, 2024 07:18
@LuciferYang
Copy link
Contributor Author

Thanks @dongjoon-hyun @HyukjinKwon ~ will merge this one.

LuciferYang added a commit that referenced this pull request Mar 20, 2024
…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 <yangjie01@baidu.com>
Signed-off-by: yangjie01 <yangjie01@baidu.com>
(cherry picked from commit 85bf761)
Signed-off-by: yangjie01 <yangjie01@baidu.com>
LuciferYang added a commit that referenced this pull request Mar 20, 2024
…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 <yangjie01@baidu.com>
Signed-off-by: yangjie01 <yangjie01@baidu.com>
(cherry picked from commit 85bf761)
Signed-off-by: yangjie01 <yangjie01@baidu.com>
@LuciferYang
Copy link
Contributor Author

Merged into master/branch-3.5/branch-3.4 ~

sweisdb pushed a commit to sweisdb/spark that referenced this pull request Apr 1, 2024
…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 apache#45582 from LuciferYang/SPARK-47455.

Authored-by: yangjie01 <yangjie01@baidu.com>
Signed-off-by: yangjie01 <yangjie01@baidu.com>
szehon-ho pushed a commit to szehon-ho/spark that referenced this pull request Aug 7, 2024
…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 apache#45582 from LuciferYang/SPARK-47455.

Authored-by: yangjie01 <yangjie01@baidu.com>
Signed-off-by: yangjie01 <yangjie01@baidu.com>
(cherry picked from commit 85bf761)
Signed-off-by: yangjie01 <yangjie01@baidu.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants