Add support for S3Object getObjectMetadata transform#6630
Merged
Conversation
alextwoods
approved these changes
Dec 16, 2025
|
|
This pull request has been closed and the conversation has been locked. Comments on closed PRs are hard for our team to see. If you need more assistance, please open a new issue that references this one. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Motivation and Context
#6469 && #6571
Fixes migration tool bug where error is thrown if code contains
S3Object.getObjectMetadata()chained to another method, e.g.object.getObjectMetadata().getCacheControl()The root cause is
S3TransformUtils.hasArguments()not working properly and always returningtrue. This occurs since OpenRewrite'sJ.MethodInvocation.getArguments()returns aList<Expression>with aJ.Emptyobject when a method has no arguments. Somethod.getArguments().isEmpty()always returnsfalse. Becuase of this, the recipe attempts to transform the getter (instead of just setters). When this getter is chained to another method, an error is thrown when the recipe attempts to castJ.MethodInvocation.getSelect()(another method) toJ.Identifier- https://github.com/aws/aws-sdk-java-v2/blob/master/v2-migration/src/main/java/software/amazon/awssdk/v2migration/S3PutObjectRequestToV2.java#L417The recipe also needs to remove the
getObjectMetadata()method. In v1,getObject()returnsS3Object. Whereas in v2,getObject()returnsResponseInputStream<GetObjectResponse>. There is noS3ObjectorObjectMetadataPOJO in v2, the metadata fields are set directly onGetObjectResponse/HeadObjectResponse.The
S3StreamingResponseToV2recipe already adds theresponse()method - https://github.com/aws/aws-sdk-java-v2/blob/master/v2-migration/src/main/java/software/amazon/awssdk/v2migration/S3StreamingResponseToV2.java#L110Modifications
S3TransformUtils.hasArguments()to properly check for args in method, by looking for anyExpressionNOT of typeJ.EmptyS3PutObjectRequestToV2recipe to remove thegetObjectMetadata()methodTaggingandGetObjectTaggingResponseinS3PojoToV2recipe, to account for when they are instantiated standalone, not assigned to a variable, e.g., passed as argTesting
getObjectMetadata()chained to another getter method, to theS3Streamingend-to-end testTypes of changes