This is an automated email from the ASF dual-hosted git repository.

smengcl pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ozone.git


The following commit(s) were added to refs/heads/master by this push:
     new 4389803780f HDDS-16835. Remove unreachable endsWith branch in S3 
ListObjects (#11467)
4389803780f is described below

commit 4389803780f99ba6765bfed061a620c954c22a50
Author: Prithvi S <[email protected]>
AuthorDate: Mon Oct 12 22:24:53 2026 +0100

    HDDS-16835. Remove unreachable endsWith branch in S3 ListObjects (#11467)
---
 .../hadoop/ozone/s3/endpoint/BucketEndpoint.java       |  8 ++------
 .../hadoop/ozone/s3/endpoint/TestBucketList.java       | 18 ++++++++++++++++++
 2 files changed, 20 insertions(+), 6 deletions(-)

diff --git 
a/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/BucketEndpoint.java
 
b/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/BucketEndpoint.java
index 3688a012c3f..9c14629bb02 100644
--- 
a/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/BucketEndpoint.java
+++ 
b/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/BucketEndpoint.java
@@ -195,6 +195,8 @@ Response handleGetRequest(S3RequestContext context, String 
bucketName) throws IO
             if (delimiterIndex >= 0) {
               // means key has multiple delimiters in its value.
               // ex: dir/dir1/dir2, where delimiter is "/" and prefix is dir/
+              // Keys that equal prefix + delimiter (ex: dir/ with prefix dir 
and
+              // delimiter /) also hit this branch and become a common prefix.
               String dirName = relativeKeyName.substring(0, delimiterIndex);
               if (!dirName.equals(prevDir)) {
                 response.addPrefix(EncodingTypeObject.createNullable(
@@ -202,12 +204,6 @@ Response handleGetRequest(S3RequestContext context, String 
bucketName) throws IO
                 prevDir = dirName;
                 count++;
               }
-            } else if (relativeKeyName.endsWith(delimiter)) {
-              // means or key is same as prefix with delimiter at end and ends 
with
-              // delimiter. ex: dir/, where prefix is dir and delimiter is /
-              response.addPrefix(
-                  EncodingTypeObject.createNullable(relativeKeyName, 
encodingType));
-              count++;
             } else {
               // means our key is matched with prefix if prefix is given and it
               // does not have any common prefix.
diff --git 
a/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestBucketList.java
 
b/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestBucketList.java
index 879cc64c08b..e6a69f95111 100644
--- 
a/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestBucketList.java
+++ 
b/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestBucketList.java
@@ -99,6 +99,24 @@ public void listDir() throws OS3Exception, IOException {
     assertEquals(0, getBucketResponse.getContents().size());
   }
 
+  /**
+   * Key equal to prefix + delimiter (dir/ with prefix dir) is handled by the
+   * indexOf(delimiter) branch as a common prefix.
+   */
+  @Test
+  public void listExactPrefixWithTrailingDelimiter() throws OS3Exception, 
IOException {
+    setup("dir/", "other");
+
+    bucketEndpoint.queryParamsForTest().set(QueryParams.DELIMITER, "/");
+    bucketEndpoint.queryParamsForTest().set(QueryParams.PREFIX, "dir");
+    ListObjectResponse response =
+        (ListObjectResponse) bucketEndpoint.get(BUCKET_NAME).getEntity();
+
+    assertEquals(1, response.getCommonPrefixes().size());
+    assertEquals("dir/", 
response.getCommonPrefixes().get(0).getPrefix().getName());
+    assertEquals(0, response.getContents().size());
+  }
+
   @Test
   public void listSubDir() throws OS3Exception, IOException {
     setup("dir1/file2", "dir1/dir2/file2", "dir1bh/file", "dir1bha/file2");


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to