Skip to content
Snippets Groups Projects
Commit 4dbb63f0 authored by James Shuster's avatar James Shuster Committed by Felix Cheung
Browse files

[SPARK-20815][SPARKR] NullPointerException in RPackageUtils#checkManifestForR

## What changes were proposed in this pull request?

- Add a null check to RPackageUtils#checkManifestForR so that jars w/o manifests don't NPE.

## How was this patch tested?

- Unit tests and manual tests.

Author: James Shuster <jshuster@palantir.com>

Closes #18040 from jrshust/feature/r-package-utils.
parent a2460be9
No related branches found
No related tags found
No related merge requests found
......@@ -92,6 +92,9 @@ private[deploy] object RPackageUtils extends Logging {
* Exposed for testing.
*/
private[deploy] def checkManifestForR(jar: JarFile): Boolean = {
if (jar.getManifest == null) {
return false
}
val manifest = jar.getManifest.getMainAttributes
manifest.getValue(hasRPackage) != null && manifest.getValue(hasRPackage).trim == "true"
}
......
......@@ -243,16 +243,22 @@ private[deploy] object IvyTestUtils {
withManifest: Option[Manifest] = None): File = {
val jarFile = new File(dir, artifactName(artifact, useIvyLayout))
val jarFileStream = new FileOutputStream(jarFile)
val manifest = withManifest.getOrElse {
val mani = new Manifest()
val manifest: Manifest = withManifest.getOrElse {
if (withR) {
val mani = new Manifest()
val attr = mani.getMainAttributes
attr.put(Name.MANIFEST_VERSION, "1.0")
attr.put(new Name("Spark-HasRPackage"), "true")
mani
} else {
null
}
mani
}
val jarStream = new JarOutputStream(jarFileStream, manifest)
val jarStream = if (manifest != null) {
new JarOutputStream(jarFileStream, manifest)
} else {
new JarOutputStream(jarFileStream)
}
for (file <- files) {
val jarEntry = new JarEntry(file._1)
......
......@@ -133,6 +133,16 @@ class RPackageUtilsSuite
}
}
test("jars without manifest return false") {
IvyTestUtils.withRepository(main, None, None) { repo =>
val jar = IvyTestUtils.packJar(new File(new URI(repo)), dep1, Nil,
useIvyLayout = false, withR = false, None)
val jarFile = new JarFile(jar)
assert(jarFile.getManifest == null, "jar file should have null manifest")
assert(!RPackageUtils.checkManifestForR(jarFile), "null manifest should return false")
}
}
test("SparkR zipping works properly") {
val tempDir = Files.createTempDir()
Utils.tryWithSafeFinally {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment