Selaa lähdekoodia

HDFS-13280. WebHDFS: Fix NPE in get snasphottable directory list call. Contributed by Lokesh Jain.

(cherry picked from commit 78b05fde6c41f7a6b2dc2d99b435d1d83242590c)
Xiaoyu Yao 7 vuotta sitten
vanhempi
commit
9d0a68721d

+ 3 - 0
hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/web/JsonUtil.java

@@ -533,6 +533,9 @@ public class JsonUtil {
 
   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]);

+ 4 - 2
hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/TestWebHDFS.java

@@ -755,14 +755,16 @@ public class TestWebHDFS {
       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();