Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

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

未关闭
#12,480 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 2 天内回复

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
25/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
停滞
技术栈
aws, java
领域
backend, cloud

调研方向

检查 v1 和 v2 SnsInterceptor 的 batch 路径,以及现有的“SNS message to phone number doesn't leak exception”测试。运行 aws-java-sns-1.0 和 aws-java-sns-2.0 测试任务;当不带 topic ARN 的 batch 请求到达 SDK 的验证错误,而不是抛出 agent NPE 时,即表示完成。

由索引模型根据 Issue 内容生成。

描述

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.

主要语言
Java
星标
737
派生
362
平均合并
3 天 18 小时
30 天内合并 PR
180

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

DataDog/dd-trace-java 的其他 Issue

查看 DataDog/dd-trace-java 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。