Skip to content

Commit 7d52777

Browse files
aarondavrxin
authored andcommitted
Super minor: Close inputStream in SparkSubmitArguments
`Properties#load()` doesn't close the InputStream, but it'd be closed after being GC'd anyway... Also changed file.getName to file, because getName only shows the filename. This will show the full (possibly relative) path, which is less confusing if it's not found. Author: Aaron Davidson <[email protected]> Closes #914 from aarondav/tiny and squashes the following commits: db9d072 [Aaron Davidson] Super minor: Close inputStream in SparkSubmitArguments
1 parent 1a0da0e commit 7d52777

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

core/src/main/scala/org/apache/spark/deploy/SparkSubmitArguments.scala

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -381,16 +381,19 @@ private[spark] class SparkSubmitArguments(args: Seq[String]) {
381381
object SparkSubmitArguments {
382382
/** Load properties present in the given file. */
383383
def getPropertiesFromFile(file: File): Seq[(String, String)] = {
384-
require(file.exists(), s"Properties file ${file.getName} does not exist")
384+
require(file.exists(), s"Properties file $file does not exist")
385+
require(file.isFile(), s"Properties file $file is not a normal file")
385386
val inputStream = new FileInputStream(file)
386-
val properties = new Properties()
387387
try {
388+
val properties = new Properties()
388389
properties.load(inputStream)
390+
properties.stringPropertyNames().toSeq.map(k => (k, properties(k).trim))
389391
} catch {
390392
case e: IOException =>
391-
val message = s"Failed when loading Spark properties file ${file.getName}"
393+
val message = s"Failed when loading Spark properties file $file"
392394
throw new SparkException(message, e)
395+
} finally {
396+
inputStream.close()
393397
}
394-
properties.stringPropertyNames().toSeq.map(k => (k, properties(k).trim))
395398
}
396399
}

0 commit comments

Comments
 (0)