-
Notifications
You must be signed in to change notification settings - Fork 924
Description
Describe the bug
The SDKPojo.sdkFieldNameToField()
method returns a map that uses Smithy locationName
values as keys instead of memberName
values. This is inconsistent with the SDK's public API which uses member names.
Looking at the generated code for S3.PutObjectRequest, the issue is clear:
private static final SdkField<String> ACL_FIELD = SdkField
.<String> builder(MarshallingType.STRING)
.memberName("ACL")
...
.traits(LocationTrait.builder().location(MarshallLocation.HEADER).locationName("x-amz-acl")
.unmarshallLocationName("x-amz-acl").build()).build();
private static final Map<String, SdkField<?>> SDK_NAME_TO_FIELD = memberNameToFieldInitializer();
@Override
public final Map<String, SdkField<?>> sdkFieldNameToField() {
return SDK_NAME_TO_FIELD;
}
private static Map<String, SdkField<?>> memberNameToFieldInitializer() {
Map<String, SdkField<?>> map = new HashMap<>();
map.put("x-amz-acl", ACL_FIELD); // ← Bug: Uses locationName instead of memberName
...
return Collections.unmodifiableMap(map);
}
The map is being populated with "x-amz-acl"
(locationName) as the key, but it should use "ACL"
(memberName) to be consistent with the public API.
Regression Issue
- Select this option if this issue appears to be a regression.
Expected Behavior
The returned map should have member names as keys (e.g., "ACL" -> ACL_FIELD)
Current Behavior
The returned map has locationName values as keys (e.g., "x-amz-acl" -> ACL_FIELD)
Reproduction Steps
// Example with S3's PutObjectRequest
PutObjectRequest request = PutObjectRequest.builder()
.bucket("my-bucket")
.key("my-key")
.acl(ObjectCannedACL.PUBLIC_READ)
.build();
Map<String, SdkField<?>> fieldMap = request.sdkFieldNameToField();
// This returns null (but shouldn't):
SdkField<?> aclField = fieldMap.get("ACL");
// This returns the field (but shouldn't be necessary):
SdkField<?> aclField = fieldMap.get("x-amz-acl");
Possible Solution
Change memberNameToFieldInitializer()
to use memberName values as keys instead of locationName values.
Additional Information/Context
- This issue appears to be most prevalent in S3 operations where many headers use the
x-amz-
prefix in their locationName - Other affected S3 fields include: ContentType, metadata headers, and other x-amz-* headers
- This impacts wrapper libraries and reflection-based utilities that expect field names to match the public API
- The method name itself (
sdkFieldNameToField
) and the method it calls (memberNameToFieldInitializer
) suggest it should map SDK field names (member names), not wire protocol names
AWS Java SDK version used
2.31.45
JDK version used
openjdk version "21.0.1" 2023-10-17 OpenJDK Runtime Environment (build 21.0.1+12-29) OpenJDK 64-Bit Server VM (build 21.0.1+12-29, mixed mode, sharing)
Operating System and version
macOS 14.7.6 (23H626)