diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileSystemStorageStatistics.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileSystemStorageStatistics.java index f179cce0c5..7c088638ea 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileSystemStorageStatistics.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileSystemStorageStatistics.java @@ -20,6 +20,7 @@ import java.util.Iterator; import java.util.NoSuchElementException; +import com.google.common.base.Preconditions; import org.apache.hadoop.classification.InterfaceAudience; import org.apache.hadoop.classification.InterfaceStability; import org.apache.hadoop.fs.FileSystem.Statistics.StatisticsData; @@ -81,6 +82,9 @@ public void remove() { } private static Long fetch(StatisticsData data, String key) { + Preconditions.checkArgument(key != null, + "The stat key of FileSystemStorageStatistics should not be null!"); + switch (key) { case "bytesRead": return data.getBytesRead(); @@ -107,6 +111,10 @@ private static Long fetch(StatisticsData data, String key) { FileSystemStorageStatistics(String name, FileSystem.Statistics stats) { super(name); + Preconditions.checkArgument(stats != null, + "FileSystem.Statistics can not be null"); + Preconditions.checkArgument(stats.getData() != null, + "FileSystem.Statistics can not have null data"); this.stats = stats; }