You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[SPARK-53136][CORE] tryWithResource & tryInitializeResource shall close resource quietly
### What changes were proposed in this pull request?
This PR modifies tryWithResource & tryInitializeResource to close the resource quietly
### Why are the changes needed?
Avoid unexpected errors, for example
We shall see
```scala
scala> tryWithResource(spark.getClass.getClassLoader.getResourceAsStream("a"))(_.readAllBytes)
java.lang.NullPointerException: Cannot invoke "java.io.InputStream.readAllBytes()" because "x$1" is null
at $anonfun$res1$2(<console>:1)
at tryWithResource(<console>:3)
... 42 elided
```
instead of
```scala
scala> tryWithResource(spark.getClass.getClassLoader.getResourceAsStream("a"))(_.readAllBytes)
java.lang.NullPointerException: Cannot invoke "java.io.Closeable.close()" because "resource" is null
at tryWithResource(<console>:4)
... 42 elided
```
### Does this PR introduce _any_ user-facing change?
no
### How was this patch tested?
new UT
### Was this patch authored or co-authored using generative AI tooling?
no
Closes#51864 from yaooqinn/SPARK-53136.
Authored-by: Kent Yao <[email protected]>
Signed-off-by: Kent Yao <[email protected]>
0 commit comments