aws / aws-sdk-java

The official AWS SDK for Java 1.x (In Maintenance Mode, End-of-Life on 12/31/2025). The AWS SDK for Java 2.x is available here: https://github.com/aws/aws-sdk-java-v2/
https://aws.amazon.com/sdkforjava
Apache License 2.0
4.13k stars 2.83k forks source link

ListNextBatchOfObjectsRequest does not retain RequestCredentialsProvider #3101

Closed jodastephen closed 5 months ago

jodastephen commented 8 months ago

Upcoming End-of-Support

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

debora-ito commented 8 months ago

@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 commented 5 months ago

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

Reference:

github-actions[bot] commented 5 months ago

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.