@@ -406,19 +406,19 @@ public Map<String, BlobMetadata> listBlobs(OperationPurpose purpose) throws IOEx
406406 public Map <String , BlobContainer > children (OperationPurpose purpose ) throws IOException {
407407 try {
408408 final var results = new HashMap <String , BlobContainer >();
409- final var relativePrefixStart = keyPath .length () + 1 ; // +1 to strip the delimiting slash
409+ final var relativePrefixStart = keyPath .length ();
410410 final var iterator = executeListing (purpose , keyPath );
411411 while (iterator .hasNext ()) {
412412 final var currentPage = iterator .next ();
413413 for (final var commonPrefix : currentPage .commonPrefixes ()) {
414- final var relativePrefix = commonPrefix .prefix (). substring ( relativePrefixStart );
415- if (relativePrefix . isEmpty () ) {
414+ final var absolutePrefix = commonPrefix .prefix ();
415+ if (absolutePrefix . length () <= relativePrefixStart + 1 ) {
416416 continue ;
417417 }
418- assert currentPage . contents ()
419- . stream ()
420- . noneMatch (s3Object -> s3Object .key ().substring ( keyPath . length ()). startsWith (relativePrefix ))
421- : "Response contained children for listed common prefix " + commonPrefix . prefix () ;
418+ final var relativePrefix = absolutePrefix . substring ( relativePrefixStart , absolutePrefix . length () - 1 );
419+ assert relativePrefix . isEmpty () == false ;
420+ assert currentPage . contents (). stream (). noneMatch (s3Object -> s3Object .key ().startsWith (absolutePrefix ))
421+ : "Response contained children for listed common prefix " + absolutePrefix ;
422422 if (results .put (relativePrefix , blobStore .blobContainer (path ().add (relativePrefix ))) != null ) {
423423 throw new IllegalStateException (
424424 "listing child containers of [" + keyPath + "] yielded multiple children with key [" + relativePrefix + "]"
0 commit comments