Skip to content

Commit c0507e0

Browse files
ulysses-youMarcelo Vanzin
authored andcommitted
[SPARK-29833][YARN] Add FileNotFoundException check for spark.yarn.jars
### What changes were proposed in this pull request? When set `spark.yarn.jars=/xxx/xxx` which is just a no schema path, spark will throw a NullPointerException. The reason is hdfs will return null if pathFs.globStatus(path) is not exist, and spark just use `pathFs.globStatus(path).filter(_.isFile())` without check it. ### Why are the changes needed? Avoid NullPointerException. ### Does this PR introduce any user-facing change? Yes. User will get a FileNotFoundException instead NullPointerException when `spark.yarn.jars` does not have schema and not exists. ### How was this patch tested? Add UT. Closes apache#26462 from ulysses-you/check-yarn-jars-path-exist. Authored-by: ulysses <[email protected]> Signed-off-by: Marcelo Vanzin <[email protected]>
1 parent 848bdfa commit c0507e0

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

resource-managers/yarn/src/main/scala/org/apache/spark/deploy/yarn/Client.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,11 @@ private[spark] class Client(
538538
if (!Utils.isLocalUri(jar)) {
539539
val path = getQualifiedLocalPath(Utils.resolveURI(jar), hadoopConf)
540540
val pathFs = FileSystem.get(path.toUri(), hadoopConf)
541-
pathFs.globStatus(path).filter(_.isFile()).foreach { entry =>
541+
val fss = pathFs.globStatus(path)
542+
if (fss == null) {
543+
throw new FileNotFoundException(s"Path ${path.toString} does not exist")
544+
}
545+
fss.filter(_.isFile()).foreach { entry =>
542546
val uri = entry.getPath().toUri()
543547
statCache.update(uri, entry)
544548
distribute(uri.toString(), targetDir = Some(LOCALIZED_LIB_DIR))

resource-managers/yarn/src/test/scala/org/apache/spark/deploy/yarn/ClientSuite.scala

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
package org.apache.spark.deploy.yarn
1919

20-
import java.io.{File, FileInputStream, FileOutputStream}
20+
import java.io.{File, FileInputStream, FileNotFoundException, FileOutputStream}
2121
import java.net.URI
2222
import java.util.Properties
2323

@@ -473,6 +473,18 @@ class ClientSuite extends SparkFunSuite with Matchers {
473473
assert(allResourceInfo.get(yarnMadeupResource).get === 5)
474474
}
475475

476+
test("test yarn jars path not exists") {
477+
withTempDir { dir =>
478+
val conf = new SparkConf().set(SPARK_JARS, Seq(dir.getAbsolutePath + "/test"))
479+
val client = new Client(new ClientArguments(Array()), conf, null)
480+
withTempDir { distDir =>
481+
intercept[FileNotFoundException] {
482+
client.prepareLocalResources(new Path(distDir.getAbsolutePath), Nil)
483+
}
484+
}
485+
}
486+
}
487+
476488
private val matching = Seq(
477489
("files URI match test1", "file:///file1", "file:///file2"),
478490
("files URI match test2", "file:///c:file1", "file://c:file2"),

0 commit comments

Comments
 (0)