Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

NullPointerException from SnsInterceptor when publishing an SNS batch without a topic ARN

Open
#12,480 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
25/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
aws, java
Domain
backend, cloud

Research direction

Inspect the v1 and v2 SnsInterceptor batch paths and the existing “SNS message to phone number doesn't leak exception” tests. Run the aws-java-sns-1.0 and aws-java-sns-2.0 test tasks; done means a batch request without a topic ARN reaches the SDK's validation error rather than throwing an agent NPE.

Written by the indexing model from the issue text.

Description

Tracer Version(s)

1.66.0

Java Version(s)

25.0.2

JVM Vendor

Eclipse Adoptium / Temurin

Bug Report

SnsInterceptor derives the DSM topic name from the topic ARN. The single-publish path handles a missing ARN, because a publish to a phone number has neither topicArn nor targetArn:

String snsTopicArn = request.topicArn();
if (null == snsTopicArn) {
  snsTopicArn = request.targetArn();
  if (null == snsTopicArn) {
    return context.request();
  }
}

The batch path dereferences it straight away:

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

PublishBatchRequest builds without a topic ARN, and the interceptor runs before marshalling, so a request that the SDK would have rejected with a validation error instead dies with an NPE thrown from the agent. Neither SDK wraps exceptions from modifyRequest (v2) or beforeMarshalling (v1), so it reaches the caller as-is:

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. I checked the other ARN parsing in the aws-java modules while I was there: AwsSdkClientDecorator guards it in v1 (if (null != topicArn)) and uses Optional.map in v2, so these two batch branches were the only unguarded ones.

Fix is up as #12457. It skips the injection and leaves the request alone, matching what the single-publish path already does. Tests mirror the existing SNS message to phone number doesn't leak exception case, and the aws-java-sns-1.0 and aws-java-sns-2.0 test tasks pass.

Filing this as an issue as well so it can be triaged and labelled. I can't set the inst:/type: labels on the PR myself.

Expected Behavior

A batch publish without a topic ARN should fail the way the SDK would fail it on its own, with a validation error. The agent should not turn it into an NPE.

Reproduction Code
SnsClient client = SnsClient.builder()
    .endpointOverride(URI.create("http://localhost:4566"))
    .region(Region.US_EAST_1)
    .build();

client.publishBatch(PublishBatchRequest.builder()
    .publishBatchRequestEntries(
        PublishBatchRequestEntry.builder().id("1").message("hello").build())
    .build());

With the agent attached this throws NullPointerException from SnsInterceptor. Without it, the SDK reports the missing topic.

Dominant language
Java
Stars
737
Forks
361
Avg merge
3d 20h
Merged PRs (30d)
173

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from DataDog/dd-trace-java

All issues in DataDog/dd-trace-java

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.