From c5dafb4ad7011181f54f53c23bdc14a734538f38 Mon Sep 17 00:00:00 2001 From: Colin Patrick Mccabe Date: Mon, 20 Jun 2016 14:25:07 -0700 Subject: [PATCH] HADOOP-13288. Guard null stats key in FileSystemStorageStatistics (Mingliang Liu via Colin P. McCabe) (cherry picked from commit 8c1f81d4bf424bdc421cf4952b230344e39a7b68) (cherry picked from commit 14df17383c20cebcdb27da1f8bce0b494d47b392) --- .../org/apache/hadoop/fs/FileSystemStorageStatistics.java | 8 ++++++++ 1 file changed, 8 insertions(+) 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 98cb70aa1b2..d85cd3ff0bb 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; @@ -77,6 +78,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(); @@ -95,6 +99,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; }