From 3161813482868e42befb618d6f5687d8ffed0e5c Mon Sep 17 00:00:00 2001 From: Sahil Takiar Date: Tue, 26 Nov 2019 11:11:26 -0800 Subject: [PATCH] HADOOP-16685: FileSystem#listStatusIterator does not check if given path exists (#1695) --- .../main/java/org/apache/hadoop/fs/FileSystem.java | 11 +++-------- .../contract/AbstractContractGetFileStatusTest.java | 8 ++++++++ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileSystem.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileSystem.java index d472591409..d2fddf8d8e 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileSystem.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileSystem.java @@ -2160,24 +2160,19 @@ protected class DirListingIterator implements private DirectoryEntries entries; private int i = 0; - DirListingIterator(Path path) { + DirListingIterator(Path path) throws IOException { this.path = path; + this.entries = listStatusBatch(path, null); } @Override public boolean hasNext() throws IOException { - if (entries == null) { - fetchMore(); - } return i < entries.getEntries().length || entries.hasMore(); } private void fetchMore() throws IOException { - byte[] token = null; - if (entries != null) { - token = entries.getToken(); - } + byte[] token = entries.getToken(); entries = listStatusBatch(path, token); i = 0; } diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/contract/AbstractContractGetFileStatusTest.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/contract/AbstractContractGetFileStatusTest.java index 85bd137813..f63314d392 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/contract/AbstractContractGetFileStatusTest.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/contract/AbstractContractGetFileStatusTest.java @@ -279,6 +279,14 @@ public void testListFilesNoDir() throws Throwable { } } + @Test + public void testListStatusIteratorNoDir() throws Throwable { + describe("test the listStatusIterator call on a path which is not " + + "present"); + intercept(FileNotFoundException.class, + () -> getFileSystem().listStatusIterator(path("missing"))); + } + @Test public void testLocatedStatusNoDir() throws Throwable { describe("test the LocatedStatus call on a path which is not present");