From 4b5bd73ac53f7de4899b5b70078249ad20216048 Mon Sep 17 00:00:00 2001 From: Naganarasimha Date: Mon, 1 May 2017 16:31:16 +0530 Subject: [PATCH] YARN-6517. Fix warnings from Spotbugs in hadoop-yarn-common. Contributed by Weiwei Yang --- .../logaggregation/AggregatedLogFormat.java | 4 ++++ .../yarn/util/ProcfsBasedProcessTree.java | 23 +++++++++++-------- 2 files changed, 17 insertions(+), 10 deletions(-) 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;