Description
Describe the bug
When the S3CrtAsyncClientBuilder is configured only with AnonymousCredentialsProvider it generates a NullPointerException.
Regression Issue
- Select this option if this issue appears to be a regression.
Expected Behavior
CrtAsyncClient should work with an open bucket when only AnonymousCredentials are set
Current Behavior
The problem is in the CrtCredentialsProviderAdapter
this.crtCredentials = new DelegateCredentialsProvider.DelegateCredentialsProviderBuilder()
.withHandler(() -> {
if (credentialsProvider instanceof AnonymousCredentialsProvider) {
return Credentials.createAnonymousCredentials();
}
AwsCredentialsIdentity sdkCredentials =
CompletableFutureUtils.joinLikeSync(credentialsProvider.resolveIdentity());
// next will generate the NPE -
// if the credentials are null it should just return new Credentials() - this worked when I ran my program in debugger
byte[] accessKey = sdkCredentials.accessKeyId().getBytes(StandardCharsets.UTF_8);
byte[] secreteKey = sdkCredentials.secretAccessKey().getBytes(StandardCharsets.UTF_8);
byte[] sessionTokens = null;
if (sdkCredentials instanceof AwsSessionCredentialsIdentity) {
sessionTokens =
((AwsSessionCredentialsIdentity) sdkCredentials).sessionToken().getBytes(StandardCharsets.UTF_8);
}
return new Credentials(accessKey, secreteKey, sessionTokens);
}).build();
Reproduction Steps
create a crt async client then run a list or getobject request against an open bucket that does not require any credentials for reading.
{
S3CrtAsyncClientBuilder asyncS3ClientBuilder = S3AsyncClient.crtBuilder();
asyncS3ClientBuilder.credentialsProvider(AnonymousCredentialsProvider.create());
S3AsyncClient asyncClient = asyncS3ClientBuilder.build();
ListObjectsV2Request listRequest = ListObjectsV2Request.builder()
.bucket(s3Adapter.getBucket())
.prefix(prefix)
.delimiter("/")
.build();
ListObjectsV2Publisher listObjectsV2Publisher = s3Adapter.getAsyncS3Client().listObjectsV2Paginator(listRequest);
......
}
Possible Solution
Change the internal.CrtCredentialsProvider's constructor
public CrtCredentialsProviderAdapter(IdentityProvider<? extends AwsCredentialsIdentity> credentialsProvider) {
this.credentialsProvider = credentialsProvider;
this.crtCredentials = new DelegateCredentialsProvider.DelegateCredentialsProviderBuilder()
.withHandler(() -> {
if (credentialsProvider instanceof AnonymousCredentialsProvider) {
return Credentials.createAnonymousCredentials();
}
AwsCredentialsIdentity sdkCredentials =
CompletableFutureUtils.joinLikeSync(credentialsProvider.resolveIdentity());
// I don't know if this is the best but when I changed the values in my debugger to avoid the NPE this worked.
if (sdkCredentials.accessKeyId() == null || sdkCredentials.secretAccessKey() == null) return new Credentials()
byte[] accessKey = sdkCredentials.accessKeyId().getBytes(StandardCharsets.UTF_8);
byte[] secreteKey = sdkCredentials.secretAccessKey().getBytes(StandardCharsets.UTF_8);
byte[] sessionTokens = null;
if (sdkCredentials instanceof AwsSessionCredentialsIdentity) {
sessionTokens =
((AwsSessionCredentialsIdentity) sdkCredentials).sessionToken().getBytes(StandardCharsets.UTF_8);
}
return new Credentials(accessKey, secreteKey, sessionTokens);
}).build();
}
Additional Information/Context
No response
AWS Java SDK version used
2.30.1
JDK version used
"1.8.0_422" - OpenJDK 64-Bit Server VM (Zulu 8.80.0.17-CA-macos-aarch64) (build 25.422-b05, mixed mode)
Operating System and version
Mac OS Sequoia 15.2