diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/web/JsonUtil.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/web/JsonUtil.java index bdb2c07b64..43a252b1c3 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/web/JsonUtil.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/web/JsonUtil.java @@ -533,6 +533,9 @@ private static Object toJsonMap( public static String toJsonString( SnapshottableDirectoryStatus[] snapshottableDirectoryList) { + if (snapshottableDirectoryList == null) { + return toJsonString("SnapshottableDirectoryList", null); + } Object[] a = new Object[snapshottableDirectoryList.length]; for (int i = 0; i < snapshottableDirectoryList.length; i++) { a[i] = toJsonMap(snapshottableDirectoryList[i]); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/TestWebHDFS.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/TestWebHDFS.java index c4e3016e2c..224735546b 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/TestWebHDFS.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/TestWebHDFS.java @@ -755,14 +755,16 @@ public void testWebHdfsSnapshottableDirectoryList() throws Exception { final Path bar = new Path("/bar"); dfs.mkdirs(foo); dfs.mkdirs(bar); + SnapshottableDirectoryStatus[] statuses = + webHdfs.getSnapshottableDirectoryList(); + Assert.assertNull(statuses); dfs.allowSnapshot(foo); dfs.allowSnapshot(bar); Path file0 = new Path(foo, "file0"); DFSTestUtil.createFile(dfs, file0, 100, (short) 1, 0); Path file1 = new Path(bar, "file1"); DFSTestUtil.createFile(dfs, file1, 100, (short) 1, 0); - SnapshottableDirectoryStatus[] statuses = - webHdfs.getSnapshottableDirectoryList(); + statuses = webHdfs.getSnapshottableDirectoryList(); SnapshottableDirectoryStatus[] dfsStatuses = dfs.getSnapshottableDirListing();