Commit 87e3861
[SPARK-56353][BUILD][TESTS][FOLLOWUP] Fix resource loading to work when resources are inside JARs
### What changes were proposed in this pull request?
This PR fixes `FileSystemNotFoundException` in `TestSpark21101Jar`, `TestUDTFJar`, and `TestHiveUdfsJar` when running tests with Maven.
These files used `Paths.get(url.toURI)` to read Java source files from classpath resources. This works with SBT where resources are extracted to `target/test-classes/` as regular files, but fails with Maven where resources may be inside JAR files, producing a `jar:file:...!/path` URI that `Paths.get()` cannot handle without a ZipFileSystem.
The fix replaces `Files.readAllBytes(Paths.get(url.toURI))` with `url.openStream().readAllBytes()`, which works regardless of whether the resource is a regular file or inside a JAR.
### Why are the changes needed?
CI runs with Maven and hits `FileSystemNotFoundException` when initializing `TestUDTFJar`, causing `CliSuite` and `HiveThriftBinaryServerSuite` to fail:
```
Cause: java.lang.ExceptionInInitializerError:
Exception java.nio.file.FileSystemNotFoundException
at jdk.zipfs/jdk.nio.zipfs.ZipFileSystemProvider.getFileSystem(ZipFileSystemProvider.java:156)
at java.base/java.nio.file.Paths.get(Paths.java:98)
at org.apache.spark.sql.hive.test.TestUDTFJar$.loadResource(TestUDTFJar.scala:37)
```
Reported in #55272 (comment)
### Does this PR introduce _any_ user-facing change?
No.
### How was this patch tested?
Verified with Maven (the environment where the failure occurs):
- CliSuite: 44/44 passed
- HiveThriftBinaryServerSuite: 30/30 passed
### Was this patch authored or co-authored using generative AI tooling?
Kiro CLI / Opus 4.6
Closes #55299 from sarutak/fix-resource-loading.
Authored-by: Kousuke Saruta <sarutak@amazon.co.jp>
Signed-off-by: Cheng Pan <chengpan@apache.org>1 parent d4b59dd commit 87e3861
3 files changed
Lines changed: 9 additions & 6 deletions
File tree
- sql/hive/src/test/scala/org/apache/spark/sql/hive/test
Lines changed: 3 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
24 | 23 | | |
25 | 24 | | |
26 | 25 | | |
| |||
64 | 63 | | |
65 | 64 | | |
66 | 65 | | |
67 | | - | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
68 | 69 | | |
69 | 70 | | |
Lines changed: 3 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
24 | 23 | | |
25 | 24 | | |
26 | 25 | | |
| |||
52 | 51 | | |
53 | 52 | | |
54 | 53 | | |
55 | | - | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
56 | 57 | | |
57 | 58 | | |
Lines changed: 3 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
24 | 23 | | |
25 | 24 | | |
26 | 25 | | |
| |||
34 | 33 | | |
35 | 34 | | |
36 | 35 | | |
37 | | - | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
38 | 39 | | |
39 | 40 | | |
40 | 41 | | |
| |||
0 commit comments