If SPECULATION_QUANTILE is set to low enough, and/or numTasks is not very high, it is possible for tasksSuccessful and minFinishedForSpeculation to be zero - causing exception while computing medianDuration within the if block : hence the added guard condition.