From ada40aa9339acf09864edb1b2669da8f3d033b5f Mon Sep 17 00:00:00 2001 From: Jason Lowe Date: Fri, 31 Oct 2014 22:53:04 +0000 Subject: [PATCH] YARN-2707. Potential null dereference in FSDownload. Contributed by Gera Shegalov (cherry picked from commit 7bc179f9f5e1e270fd5e6f1ad29b0f32fe371d15) --- hadoop-yarn-project/CHANGES.txt | 3 +++ .../org/apache/hadoop/yarn/util/FSDownload.java | 13 +++++-------- .../org/apache/hadoop/yarn/util/TestFSDownload.java | 3 +-- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/hadoop-yarn-project/CHANGES.txt b/hadoop-yarn-project/CHANGES.txt index bf421423418..96e5b2b25d3 100644 --- a/hadoop-yarn-project/CHANGES.txt +++ b/hadoop-yarn-project/CHANGES.txt @@ -796,6 +796,9 @@ Release 2.6.0 - UNRELEASED modified in YARN-2698 so that tests in YARN frameworks don't break. (Wangda Tan via vinodkv) + YARN-2707. Potential null dereference in FSDownload (Gera Shegalov via + jlowe) + Release 2.5.1 - 2014-09-05 INCOMPATIBLE CHANGES diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/util/FSDownload.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/util/FSDownload.java index 8cc5ed36069..fb37701d5ec 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/util/FSDownload.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/util/FSDownload.java @@ -266,7 +266,7 @@ public class FSDownload implements Callable { return dCopy; } - private long unpack(File localrsrc, File dst, Pattern pattern) throws IOException { + private long unpack(File localrsrc, File dst) throws IOException { switch (resource.getType()) { case ARCHIVE: { String lowerDst = dst.getName().toLowerCase(); @@ -290,7 +290,9 @@ public class FSDownload implements Callable { case PATTERN: { String lowerDst = dst.getName().toLowerCase(); if (lowerDst.endsWith(".jar")) { - RunJar.unJar(localrsrc, dst, pattern); + String p = resource.getPattern(); + RunJar.unJar(localrsrc, dst, + p == null ? RunJar.MATCH_ANY : Pattern.compile(p)); File newDst = new File(dst, dst.getName()); if (!dst.exists() && !dst.mkdir()) { throw new IOException("Unable to create directory: [" + dst + "]"); @@ -356,12 +358,7 @@ public class FSDownload implements Callable { return files.makeQualified(copy(sCopy, dst_work)); }; }); - Pattern pattern = null; - String p = resource.getPattern(); - if (p != null) { - pattern = Pattern.compile(p); - } - unpack(new File(dTmp.toUri()), new File(dFinal.toUri()), pattern); + unpack(new File(dTmp.toUri()), new File(dFinal.toUri())); changePermissions(dFinal.getFileSystem(conf), dFinal); files.rename(dst_work, destDirPath, Rename.OVERWRITE); } catch (Exception e) { diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/util/TestFSDownload.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/util/TestFSDownload.java index 02ba5fa3b40..07dd63006fb 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/util/TestFSDownload.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/util/TestFSDownload.java @@ -500,9 +500,8 @@ public class TestFSDownload { pending.put(rsrc, exec.submit(fsd)); exec.shutdown(); while (!exec.awaitTermination(1000, TimeUnit.MILLISECONDS)); - Assert.assertTrue(pending.get(rsrc).isDone()); - try { + pending.get(rsrc).get(); // see if there was an Exception during download FileStatus[] filesstatus = files.getDefaultFileSystem().listStatus( basedir); for (FileStatus filestatus : filesstatus) {