aws-sdk-java icon indicating copy to clipboard operation
aws-sdk-java copied to clipboard

ListNextBatchOfObjectsRequest does not retain RequestCredentialsProvider

Open jodastephen opened this issue 1 year ago • 1 comments

Upcoming End-of-Support

  • [X] I acknowledge the upcoming end-of-support for AWS SDK for Java v1 was announced, and migration to AWS SDK for Java v2 is recommended.

Describe the bug

The method AmazonS3Client::listNextBatchOfObjects(ListNextBatchOfObjectsRequest) takes a standard request object that contains the property RequestCredentialsProvider (inherited from AmazonWebServiceRequest). However, the implementation uses the method ListNextBatchOfObjectsRequest::toListObjectsRequest() which does not copy the credentials provider (and other properties) to the ListObjectsRequest. As a result, our code failed to have the correct credentials to query S3.

Expected Behavior

The code should copy the request credentials across. The class ListNextBatchOfVersionsRequest does this correctly.

Current Behavior

This is the broken code in ListNextBatchOfObjectsRequest:

    public ListObjectsRequest toListObjectsRequest() {
        return new ListObjectsRequest(previousObjectListing.getBucketName(),
                previousObjectListing.getPrefix(),
                previousObjectListing.getNextMarker(),
                previousObjectListing.getDelimiter(),
                Integer.valueOf(previousObjectListing.getMaxKeys()))
                .withEncodingType(previousObjectListing.getEncodingType());
    }

This is the correct kind of code in ListNextBatchOfVersionsRequest, note how the extra properties are copied across:

    public ListVersionsRequest toListVersionsRequest() {
        ListVersionsRequest result = new ListVersionsRequest(previousVersionListing.getBucketName(),
                                                             previousVersionListing.getPrefix(),
                                                             previousVersionListing.getNextKeyMarker(),
                                                             previousVersionListing.getNextVersionIdMarker(),
                                                             previousVersionListing.getDelimiter(),
                                                             previousVersionListing.getMaxKeys())
            .withEncodingType(previousVersionListing.getEncodingType())
            .withRequestCredentialsProvider(getRequestCredentialsProvider())
            .withGeneralProgressListener(getGeneralProgressListener())
            .withRequestMetricCollector(getRequestMetricCollector());

        Integer sdkClientExecutionTimeout = getSdkClientExecutionTimeout();
        if (sdkClientExecutionTimeout != null) {
            result.setSdkClientExecutionTimeout(sdkClientExecutionTimeout);
        }

        Integer sdkRequestTimeout = getSdkRequestTimeout();
        if (sdkClientExecutionTimeout != null) {
            result.setSdkRequestTimeout(sdkRequestTimeout);
        }

        return result;
    }

Reproduction Steps

No need for SSCCE. Information above is sufficient.

Possible Solution

No response

Additional Information/Context

The git repo shows the code is still broken https://github.com/aws/aws-sdk-java/blob/master/aws-java-sdk-s3/src/main/java/com/amazonaws/services/s3/model/ListNextBatchOfObjectsRequest.java#L74

AWS Java SDK version used

1.12.609

JDK version used

8

Operating System and version

Windows 11

jodastephen avatar Mar 20 '24 09:03 jodastephen

@jodastephen bug acknowledged. But we probably won't fix it before maintenance mode phase.

The recommendation here is to use Java SDK v2 built-in Paginators - https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/services/s3/S3Client.html#listObjectsV2Paginator(java.util.function.Consumer)

debora-ito avatar Mar 29 '24 20:03 debora-ito

Closing this, we don't have plans to fix before going into Maintenance Mode.

Reference:

  • Announcing end-of-support for AWS SDK for Java v1.x effective December 31, 2025 - blog post

debora-ito avatar Jun 20 '24 01:06 debora-ito

This issue is now closed.

Comments on closed issues are hard for our team to see. If you need more assistance, please open a new issue that references this one.

github-actions[bot] avatar Jun 20 '24 01:06 github-actions[bot]