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 @@ public class JsonUtil {
public static String toJsonString( public static String toJsonString(
SnapshottableDirectoryStatus[] snapshottableDirectoryList) { SnapshottableDirectoryStatus[] snapshottableDirectoryList) {
if (snapshottableDirectoryList == null) {
return toJsonString("SnapshottableDirectoryList", null);
}
Object[] a = new Object[snapshottableDirectoryList.length]; Object[] a = new Object[snapshottableDirectoryList.length];
for (int i = 0; i < snapshottableDirectoryList.length; i++) { for (int i = 0; i < snapshottableDirectoryList.length; i++) {
a[i] = toJsonMap(snapshottableDirectoryList[i]); a[i] = toJsonMap(snapshottableDirectoryList[i]);

View File

@ -755,14 +755,16 @@ public class TestWebHDFS {
final Path bar = new Path("/bar"); final Path bar = new Path("/bar");
dfs.mkdirs(foo); dfs.mkdirs(foo);
dfs.mkdirs(bar); dfs.mkdirs(bar);
SnapshottableDirectoryStatus[] statuses =
webHdfs.getSnapshottableDirectoryList();
Assert.assertNull(statuses);
dfs.allowSnapshot(foo); dfs.allowSnapshot(foo);
dfs.allowSnapshot(bar); dfs.allowSnapshot(bar);
Path file0 = new Path(foo, "file0"); Path file0 = new Path(foo, "file0");
DFSTestUtil.createFile(dfs, file0, 100, (short) 1, 0); DFSTestUtil.createFile(dfs, file0, 100, (short) 1, 0);
Path file1 = new Path(bar, "file1"); Path file1 = new Path(bar, "file1");
DFSTestUtil.createFile(dfs, file1, 100, (short) 1, 0); DFSTestUtil.createFile(dfs, file1, 100, (short) 1, 0);
SnapshottableDirectoryStatus[] statuses = statuses = webHdfs.getSnapshottableDirectoryList();
webHdfs.getSnapshottableDirectoryList();
SnapshottableDirectoryStatus[] dfsStatuses = SnapshottableDirectoryStatus[] dfsStatuses =
dfs.getSnapshottableDirListing(); dfs.getSnapshottableDirListing();