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

This commit is contained in:
Xiaoyu Yao 2018-03-15 10:47:29 -07:00
parent e71bc00a47
commit 78b05fde6c
2 changed files with 7 additions and 2 deletions

View File

@ -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]);

View File

@ -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();