diff --git a/hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3native/NativeS3FileSystem.java b/hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3native/NativeS3FileSystem.java index f7412989c1f..1a45db311ea 100644 --- a/hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3native/NativeS3FileSystem.java +++ b/hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3native/NativeS3FileSystem.java @@ -587,7 +587,12 @@ public class NativeS3FileSystem extends FileSystem { for (String commonPrefix : listing.getCommonPrefixes()) { Path subpath = keyToPath(commonPrefix); String relativePath = pathUri.relativize(subpath.toUri()).getPath(); - status.add(newDirectory(new Path(absolutePath, relativePath))); + // sometimes the common prefix includes the base dir (HADOOP-13830). + // avoid that problem by detecting it and keeping it out + // of the list + if (!relativePath.isEmpty()) { + status.add(newDirectory(new Path(absolutePath, relativePath))); + } } priorLastKey = listing.getPriorLastKey(); } while (priorLastKey != null);