Skip to content

Prevent NPE in HttpClientDecorator.isAgentRequest for a null request - #12376

Open
dougqh wants to merge 2 commits into
masterfrom
dougqh/fix-httpclient-null-request-npe
Open

Prevent NPE in HttpClientDecorator.isAgentRequest for a null request#12376
dougqh wants to merge 2 commits into
masterfrom
dougqh/fix-httpclient-null-request-npe

Conversation

@dougqh

@dougqh dougqh commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

What Does This Do

Guards HttpClientDecorator.isAgentRequest(REQUEST) against a null request, returning false instead of throwing an NPE from inside getRequestHeader. Adds a JUnit 5 regression test.

Motivation

ByteBuddy method advice runs before the instrumented method's own argument validation. So when a caller passes a null HttpRequest (e.g. httpClient.sendAsync(null, bodyHandler)), our SendAsyncAdvice/SendAdvice for the java.net.http instrumentation dereferences it first via isAgentRequest(request)getRequestHeader(request, ...) and NPEs — before the JDK's own null-check on that same argument ever gets a chance to fire its own, correctly-attributed NPE.

The advice's suppress = Throwable.class keeps this from breaking the caller (the real method still runs afterward and throws its own NPE as expected), but the swallowed exception is logged/recorded as an instrumentation failure ("Failed to handle exception in instrumentation for ... - SendAsyncAdvice"), which is what surfaced this NPE misattributed as an instrumentation bug in Datadog error tracking (issue 83642586-aab1-11f0-a63b-da7ad0900002).

Fixing in the shared HttpClientDecorator base class rather than only in JavaNetClientDecorator so every HTTP client integration built on it is protected the same way.

Additional Notes

techdebt and perf-review skills were run over this branch: no findings from either — isAgentRequest is on the per-request hot path, but the added guard is a single cheap null check with no allocation.

Contributor Checklist

  • Format the title according to the contribution guidelines
  • Assign the type: and (comp: or inst:) labels in addition to any other useful labels
  • Avoid using close, fix, or any linking keywords when referencing an issue
  • Update the CODEOWNERS file on source file addition, migration, or deletion
  • Update public documentation with any new configuration flags or behaviors
  • Once approved, use merge queue to merge the PR

Jira ticket: N/A

ByteBuddy advice runs before the instrumented method's own argument
validation, so a caller passing a null request (e.g.
httpClient.sendAsync(null, ...)) NPEs inside isAgentRequest ->
getRequestHeader before the JDK's own null-check gets a chance to
fire, producing a spurious "Failed to handle exception in
instrumentation" telemetry entry instead of the real NPE the JDK
would have thrown.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@dougqh dougqh added tag: ai generated Largely based on code generated by an AI or LLM type: bug fix Bug fix inst: java Core Java language instrumentation labels Sep 2, 2026
@dougqh
dougqh marked this pull request as ready for review September 2, 2026 03:04
@dougqh
dougqh requested a review from a team as a code owner September 2, 2026 03:04
@dougqh
dougqh requested review from AlexeyKuznetsov-DD and removed request for a team September 2, 2026 03:04

@datadog-prod-us1-4 datadog-prod-us1-4 Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Datadog Autotest: PASS

More details

The null guard stops advice from reading headers from a null request. It preserves the instrumented method's own argument validation.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Datadog Autotest · Commit 49b13a5 · What is Autotest? · @DataDog review to ask questions · Any feedback? Reach out in #autotest

@datadog-prod-us1-4

This comment has been minimized.

@dd-octo-sts

dd-octo-sts Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

🟢 Java Benchmark SLOs — All performance SLOs passed

Suite Status
Startup 🟢 pass

SLO thresholds are defined here based on automatically generated metrics. A warning is raised when results are within 5% of the threshold.

PR vs. master results
Scenario Candidate master Δ (95% CI of mean)
startup:insecure-bank:iast:Agent 13.98 s 13.96 s [-0.5%; +0.8%] (no difference)
startup:insecure-bank:tracing:Agent 12.96 s 12.96 s [-0.7%; +0.7%] (no difference)
startup:petclinic:appsec:Agent 16.96 s 16.82 s [-0.1%; +1.7%] (no difference)
startup:petclinic:iast:Agent 16.87 s 16.87 s [-0.6%; +0.7%] (no difference)
startup:petclinic:profiling:Agent 16.50 s 16.81 s [-2.7%; -1.0%] (significantly better)
startup:petclinic:sca:Agent 16.40 s 16.75 s [-6.4%; +2.2%] (no difference)
startup:petclinic:tracing:Agent 16.08 s 16.07 s [-0.8%; +0.9%] (no difference)

Commit: f7b3f21b · CI Pipeline · Benchmarking Platform UI


Load and DaCapo benchmarks can be triggered manually in the GitLab pipeline. Results will appear in the Benchmarking Platform UI after completion.

@dougqh
dougqh added this pull request to the merge queue Sep 2, 2026
@dd-octo-sts

dd-octo-sts Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

/merge

@gh-worker-devflow-routing-ef8351

gh-worker-devflow-routing-ef8351 Bot commented Sep 2, 2026

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2026-09-02 12:57:26 UTC ℹ️ Start processing command /merge


2026-09-02 12:57:32 UTC ℹ️ MergeQueue: pull request added to the queue

The expected merge time in master is approximately 1h (p90).


2026-09-02 13:15:15 UTCMergeQueue: The build pipeline contains failing jobs for this merge request

Build pipeline has failing jobs for 310723a:

⚠️ Do NOT retry failed jobs directly (why?).

What to do next?

  • Investigate the failures and when ready, re-add your pull request to the queue!
  • If your PR checks are green, try to rebase/merge. It might be because the CI run is a bit old.
  • Any question, go check the FAQ.
Details

Since those jobs are not marked as being allowed to fail, the pipeline will most likely fail.
Therefore, and to allow other builds to be processed, this merge request has been rejected and the pipeline got canceled.

@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Sep 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

inst: java Core Java language instrumentation tag: ai generated Largely based on code generated by an AI or LLM type: bug fix Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants