From df8cd1351848eef56455f3116f3970923e1426c3 Mon Sep 17 00:00:00 2001
From: Todd Lipcon <todd@cloudera.com>
Date: Fri, 9 Oct 2009 17:52:10 -0700
Subject: [PATCH] MAPREDUCE-1089. Fix bug in Fair Scheduler where preemption would throw a NPE when facing tasks in "scheduled but not running" status

---
 .../org/apache/hadoop/mapred/FairScheduler.java    |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/src/contrib/fairscheduler/src/java/org/apache/hadoop/mapred/FairScheduler.java b/src/contrib/fairscheduler/src/java/org/apache/hadoop/mapred/FairScheduler.java
index 22ba480..4c188f4 100644
--- a/src/contrib/fairscheduler/src/java/org/apache/hadoop/mapred/FairScheduler.java
+++ b/src/contrib/fairscheduler/src/java/org/apache/hadoop/mapred/FairScheduler.java
@@ -1003,9 +1003,14 @@ public class FairScheduler extends TaskScheduler {
     List<TaskStatus> statuses = new ArrayList<TaskStatus>();
     for (TaskInProgress tip: tips) {
       for (TaskAttemptID id: tip.getActiveTasks().keySet()) {
-        statuses.add(tip.getTaskStatus(id));
+        TaskStatus stat = tip.getTaskStatus(id);
+        // status is null when the task has been scheduled but not yet running
+        if (stat != null) {
+          statuses.add(stat);
+        }
       }
     }
+
     // Sort the statuses in order of start time, with the latest launched first
     Collections.sort(statuses, new Comparator<TaskStatus>() {
       public int compare(TaskStatus t1, TaskStatus t2) {
-- 
1.6.0.4

