diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/logaggregation/AggregatedLogFormat.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/logaggregation/AggregatedLogFormat.java index 0aa318c8ce..e5cb2553a8 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/logaggregation/AggregatedLogFormat.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/logaggregation/AggregatedLogFormat.java @@ -310,6 +310,10 @@ public String getUser() { } private Set getPendingLogFilesToUpload(File containerLogDir) { + if(containerLogDir == null || + containerLogDir.listFiles() == null) { + return new HashSet<>(0); + } Set candidates = new HashSet(Arrays.asList(containerLogDir.listFiles())); for (File logFile : candidates) { diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/util/ProcfsBasedProcessTree.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/util/ProcfsBasedProcessTree.java index d54611e817..7f81c5b898 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/util/ProcfsBasedProcessTree.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/util/ProcfsBasedProcessTree.java @@ -481,18 +481,21 @@ private static String getValidPID(String pid) { * Get the list of all processes in the system. */ private List getProcessList() { - String[] processDirs = (new File(procfsDir)).list(); List processList = new ArrayList(); - - for (String dir : processDirs) { - Matcher m = numberPattern.matcher(dir); - if (!m.matches()) continue; - try { - if ((new File(procfsDir, dir)).isDirectory()) { - processList.add(dir); + String[] processDirs = (new File(procfsDir)).list(); + if (processDirs != null) { + for (String dir : processDirs) { + Matcher m = numberPattern.matcher(dir); + if (!m.matches()) { + continue; + } + try { + if ((new File(procfsDir, dir)).isDirectory()) { + processList.add(dir); + } + } catch (SecurityException s) { + // skip this process } - } catch (SecurityException s) { - // skip this process } } return processList;