hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fab...@apache.org
Subject hadoop git commit: HADOOP-14504 ProvidedFileStatusIterator#next() may throw IndexOutOfBoundsException (Aaron Fabbri)
Date Thu, 08 Jun 2017 22:56:22 GMT
Repository: hadoop
Updated Branches:
  refs/heads/HADOOP-13345 30baa089d -> 6a06ed834


HADOOP-14504 ProvidedFileStatusIterator#next() may throw IndexOutOfBoundsException (Aaron
Fabbri)


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/6a06ed83
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/6a06ed83
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/6a06ed83

Branch: refs/heads/HADOOP-13345
Commit: 6a06ed834bcceae7b65305d49b65c4bf6a7438ad
Parents: 30baa08
Author: Aaron Fabbri <fabbri@apache.org>
Authored: Thu Jun 8 15:55:20 2017 -0700
Committer: Aaron Fabbri <fabbri@apache.org>
Committed: Thu Jun 8 15:55:20 2017 -0700

----------------------------------------------------------------------
 .../java/org/apache/hadoop/fs/s3a/Listing.java  |  3 +++
 .../org/apache/hadoop/fs/s3a/TestListing.java   | 24 ++++++++++++++++++++
 2 files changed, 27 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/6a06ed83/hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/Listing.java
----------------------------------------------------------------------
diff --git a/hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/Listing.java b/hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/Listing.java
index b45fc43..5299c6c 100644
--- a/hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/Listing.java
+++ b/hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/Listing.java
@@ -271,6 +271,9 @@ public class Listing {
 
     @Override
     public FileStatus next() throws IOException {
+      if (!hasNext()) {
+        throw new NoSuchElementException();
+      }
       return filteredStatusList.get(index++);
     }
   }

http://git-wip-us.apache.org/repos/asf/hadoop/blob/6a06ed83/hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/TestListing.java
----------------------------------------------------------------------
diff --git a/hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/TestListing.java
b/hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/TestListing.java
index 43eb2c0..e647327 100644
--- a/hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/TestListing.java
+++ b/hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/TestListing.java
@@ -29,8 +29,12 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashSet;
 import java.util.Iterator;
+import java.util.NoSuchElementException;
 import java.util.Set;
 
+import static org.apache.hadoop.fs.s3a.Listing.ACCEPT_ALL;
+import static org.apache.hadoop.fs.s3a.Listing.ProvidedFileStatusIterator;
+
 /**
  * Place for the S3A listing classes; keeps all the small classes under control.
  */
@@ -91,4 +95,24 @@ public class TestListing extends AbstractS3AMockTest {
     }
     Assert.assertTrue(actualPaths.equals(expectedPaths));
   }
+
+  @Test
+  public void testProvidedFileStatusIteratorEnd() throws Exception {
+    FileStatus[] statuses = {
+        new FileStatus(100, false, 1, 8192, 0, new Path("s3a://blah/blah"))
+    };
+    ProvidedFileStatusIterator it = new ProvidedFileStatusIterator(statuses,
+        ACCEPT_ALL, new Listing.AcceptAllButS3nDirs());
+
+    Assert.assertTrue("hasNext() should return true first time", it.hasNext());
+    Assert.assertNotNull("first element should not be null", it.next());
+    Assert.assertFalse("hasNext() should now be false", it.hasNext());
+    try {
+      it.next();
+      Assert.fail("next() should have thrown exception");
+    } catch (NoSuchElementException e) {
+      // Correct behavior.  Any other exceptions are propagated as failure.
+      return;
+    }
+  }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org


Mime
View raw message