HDFS-4778. Fixes some issues that the first patch on HDFS-2576 missed. Contributed by Devaraj Das.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1477849 13f79535-47bb-0310-9956-ffa450edef68