Skip to content

Skip storing the dispatcher target when the servlet context returns no dispatcher (quick fix) - #12802

Merged
gh-worker-dd-mergequeue-cf854d[bot] merged 1 commit into
masterfrom
dougqh/weakmap-put-null-key
Oct 9, 2026
Merged

gh-worker-dd-mergequeue-cf854d[bot] merged 1 commit into
masterfrom
dougqh/weakmap-put-null-key

Conversation

@dougqh

@dougqh dougqh commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

What Does This Do

ServletContextInstrumentation.RequestDispatcherTargetAdvice now returns early when getRequestDispatcher / getNamedDispatcher returns null, instead of using the null dispatcher as a context-store key.

Motivation

Error Tracking: https://app.datadoghq.com/error-tracking/issue/7ddef69a-aab1-11f0-8060-da7ad0900002 ("Failed to handle exception in instrumentation for org.apache.catalina.core.ApplicationContext"):

java.lang.NullPointerException
  at datadog.trace.agent.tooling.WeakMaps$Adapter.put(WeakMaps.java:75)
  at datadog.trace.bootstrap.WeakMapContextStore.put(WeakMapContextStore.java:31)
  at ... (advice on org.apache.catalina.core.ApplicationContext)

Servlet containers return null for an unknown path or servlet name. Tomcat's ApplicationContext does this, for example. A null key fails the KeyWithValue check in FieldBackedContextStore, so it falls through to the weak-map fallback, and WeakConcurrentMap rejects null keys. The error was suppressed and logged, so it didn't break the app, but it showed up as noise in instrumentation telemetry.

This is the put-side companion of #12692, which fixed the get side (a null servlet context key in the IAST getSession advice).

Additional Notes

  • New JUnit 5 test ServletContextNullDispatcherTest (javax-servlet-common). It uses a ServletContext that returns null dispatchers. Before the fix it fails through AbstractInstrumentationTest's instrumentation-error check, with the same WeakMaps$Adapter.put(WeakMaps.java:75) NPE stack as production. After the fix it passes.
  • :dd-java-agent:instrumentation:servlet:javax-servlet:javax-servlet-common:test, spotlessCheck and spotbugsMain pass.
  • There is no jakarta counterpart of this advice, so no other call site needs the change.

🤖 Generated with Claude Code

…o dispatcher

ServletContext.getRequestDispatcher/getNamedDispatcher return null for an unknown
path or servlet name (e.g. Tomcat's ApplicationContext). The exit advice then used
that null dispatcher as a context store key, which throws an NPE in the weak-map
fallback.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dougqh dougqh added type: bug fix Bug fix tag: ai generated Largely based on code generated by an AI or LLM inst:servlet Servlet instrumentation labels Oct 8, 2026
@dougqh
dougqh requested a review from mcculls October 8, 2026 19:33
@dougqh
dougqh marked this pull request as ready for review October 8, 2026 19:34
@dougqh
dougqh requested a review from a team as a code owner October 8, 2026 19:34
@dougqh
dougqh requested review from ygree and removed request for a team October 8, 2026 19:34
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

@dougqh dougqh changed the title Skip storing the dispatcher target when the servlet context returns no dispatcher Skip storing the dispatcher target when the servlet context returns no dispatcher (quick fix) Oct 8, 2026

@datadog-datadog-us1-prod datadog-datadog-us1-prod 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.

Bits Code Review: PASS

More details

The null guard prevents missing dispatchers from reaching the context store while preserving target storage for non-null dispatchers. Regression coverage addresses both dispatcher lookup methods.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit 6858d09 · @DataDog review to ask questions

@datadog-datadog-us1-prod

This comment has been minimized.

@dd-octo-sts

dd-octo-sts Bot commented Oct 8, 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 14.62 s 14.64 s [-0.9%; +0.6%] (no difference)
startup:insecure-bank:tracing:Agent 13.56 s 13.53 s [-0.5%; +1.0%] (no difference)
startup:petclinic:appsec:Agent 17.65 s 17.48 s [+0.2%; +1.8%] (maybe worse)
startup:petclinic:iast:Agent 17.30 s 17.45 s [-1.7%; +0.0%] (no difference)
startup:petclinic:profiling:Agent 17.32 s 16.59 s [+0.2%; +8.5%] (maybe worse)
startup:petclinic:sca:Agent 17.63 s 17.56 s [-0.6%; +1.3%] (no difference)
startup:petclinic:tracing:Agent 16.50 s 16.21 s [-2.5%; +6.2%] (no difference)

Commit: 6858d091 · 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 Oct 9, 2026
@dd-octo-sts

dd-octo-sts Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

/merge

@gh-worker-devflow-routing-ef8351

gh-worker-devflow-routing-ef8351 Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2026-10-09 19:06:53 UTC ℹ️ Start processing command /merge


2026-10-09 19:06:57 UTC ℹ️ MergeQueue: pull request added to the queue

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


2026-10-09 20:00:58 UTC ❌ MergeQueue: The build pipeline contains failing jobs for this merge request

Build pipeline has failing jobs for 4fc605b:

⚠️ 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 Oct 9, 2026
@dougqh
dougqh added this pull request to the merge queue Oct 9, 2026
@dd-octo-sts

dd-octo-sts Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

/merge

@gh-worker-devflow-routing-ef8351

gh-worker-devflow-routing-ef8351 Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2026-10-09 20:20:53 UTC ℹ️ Start processing command /merge


2026-10-09 20:20:58 UTC ℹ️ MergeQueue: pull request added to the queue

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


2026-10-09 22:07:30 UTC ℹ️ MergeQueue: This merge request was merged

@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 9, 2026
@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot merged commit c9fb9f1 into master Oct 9, 2026
620 of 626 checks passed
@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot deleted the dougqh/weakmap-put-null-key branch October 9, 2026 22:07
@github-actions github-actions Bot added this to the 1.68.0 milestone Oct 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

inst:servlet Servlet 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.

2 participants