Skip to content

Fix NullPointerException when publishing an SNS batch without a topic ARN - #12457

Open
anjeongkyun wants to merge 1 commit into
DataDog:masterfrom
anjeongkyun:fix/sns-batch-null-topic-arn
Open

Fix NullPointerException when publishing an SNS batch without a topic ARN#12457
anjeongkyun wants to merge 1 commit into
DataDog:masterfrom
anjeongkyun:fix/sns-batch-null-topic-arn

Conversation

@anjeongkyun

Copy link
Copy Markdown

SnsInterceptor reads the topic ARN to derive the topic name for DSM. The single-publish path already handles a missing ARN (a publish to a phone number has neither topicArn nor targetArn), but the batch path dereferences it straight away:

String snsTopicArn = request.topicArn();
String snsTopicName = snsTopicArn.substring(snsTopicArn.lastIndexOf(':') + 1);

PublishBatchRequest builds fine without a topic ARN, and the interceptor runs before marshalling, so a request that AWS would have rejected with a validation error instead fails with an NPE thrown from the agent. Neither SDK wraps exceptions from modifyRequest/beforeMarshalling, so it surfaces to the caller as-is.

Without the change, the new test fails like this:

Expected exception of type 'software.amazon.awssdk.core.exception.SdkException',
but got 'java.lang.NullPointerException'
Caused by: java.lang.NullPointerException: Cannot invoke "String.lastIndexOf(int)"
  because "snsTopicArn" is null
	at datadog.trace.instrumentation.aws.v2.sns.SnsInterceptor.modifyRequest

Both the v1 and v2 interceptors have it, so both are fixed the same way the single-publish path already does: skip the injection and leave the request alone.

I checked the other ARN parsing in the aws-java modules while I was here. AwsSdkClientDecorator guards it in v1 (if (null != topicArn)) and uses Optional.map in v2, so the two batch branches were the only unguarded ones.

Tests mirror the existing SNS message to phone number doesn't leak exception case. aws-java-sns-1.0 and aws-java-sns-2.0 test tasks pass, spotlessApply is clean.

Could a maintainer add inst: aws and type: bug? I can't set labels on this repo.

@anjeongkyun
anjeongkyun marked this pull request as ready for review September 11, 2026 06:40
@anjeongkyun
anjeongkyun requested review from a team as code owners September 11, 2026 06:40
@anjeongkyun
anjeongkyun requested review from vandonr and removed request for a team September 11, 2026 06:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant