Skip to content

Fix NPE in JDBC instrumentation when connection has no database type - #12371

Merged
gh-worker-dd-mergequeue-cf854d[bot] merged 4 commits into
masterfrom
dougqh/fix-database-client-decorator-npe
Sep 10, 2026
Merged

gh-worker-dd-mergequeue-cf854d[bot] merged 4 commits into
masterfrom
dougqh/fix-database-client-decorator-npe

Conversation

@dougqh

@dougqh dougqh commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

What Does This Do

Guards DatabaseClientDecorator.processDatabaseType() and dbService() against a null dbType, instead of letting them NPE.

CACHE.computeIfAbsent(dbType, NamingEntry::new) returns null for a null key without invoking the producer (FixedSizeCache.computeIfAbsent, internal-api/.../FixedSizeCache.java:71-73). When dbType is null — e.g. JDBCDecorator.onConnection passing a DBInfo.getType() that couldn't be determined — the returned NamingEntry was dereferenced immediately afterward, throwing an NPE inside tracer instrumentation instead of degrading gracefully.

  • processDatabaseType/dbService: check dbType == null up front and return early, rather than inferring the null case from the cache's return value.
  • Added DatabaseClientDecoratorNullDbTypeTest covering both methods with a null dbType.

Motivation

Fixes a NullPointerException reported in Error Tracking (issue, 1300+ occurrences, first seen 2026-02-16, service mainframe-gateway via JDBC instrumentation):

java.lang.NullPointerException
  at DatabaseClientDecorator$NamingEntry.access$000(DatabaseClientDecorator.java:25)
  at DatabaseClientDecorator.processDatabaseType(DatabaseClientDecorator.java:148)
  at JDBCDecorator.onConnection(JDBCDecorator.java:158)

Additional Notes

/techdebt and /perf-review both came back clean: no duplication/complexity concerns, and the null-guards are a strict improvement on the previously-crashing path with no added cost on the normal path.

🤖 Generated with Claude Code

Contributor Checklist

Jira ticket: [PROJ-IDENT]

@dougqh dougqh added tag: ai generated Largely based on code generated by an AI or LLM type: bug fix Bug fix comp: database Database Monitoring labels Sep 1, 2026
@dd-octo-sts

dd-octo-sts Bot commented Sep 1, 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.91 s 13.97 s [-1.2%; +0.3%] (no difference)
startup:insecure-bank:tracing:Agent 12.87 s 12.95 s [-1.1%; -0.2%] (maybe better)
startup:petclinic:appsec:Agent 17.49 s 16.78 s [-0.1%; +8.5%] (no difference)
startup:petclinic:iast:Agent 17.37 s 17.59 s [-2.4%; -0.2%] (maybe better)
startup:petclinic:profiling:Agent 17.43 s 17.44 s [-1.1%; +1.0%] (no difference)
startup:petclinic:sca:Agent 17.01 s 17.44 s [-6.8%; +1.8%] (no difference)
startup:petclinic:tracing:Agent 16.75 s 16.71 s [-0.6%; +1.0%] (no difference)

Commit: a73dddf0 · 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 force-pushed the dougqh/fix-database-client-decorator-npe branch from 343288d to bec931e Compare September 2, 2026 01:10
processDatabaseType/dbService dereferenced the NamingEntry returned by
CACHE.computeIfAbsent(dbType, NamingEntry::new) without checking for
null. FixedSizeCache.computeIfAbsent returns null for a null key
without invoking the producer, so a null dbType() (e.g. an
undetermined DBInfo.getType()) led to a NullPointerException in
tracing instrumentation instead of a graceful no-op.

Guard on dbType == null directly instead of inferring it from the
cache's return value, and add a test exercising both methods with a
null dbType.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@dougqh
dougqh force-pushed the dougqh/fix-database-client-decorator-npe branch from bec931e to 0dd0abe Compare September 2, 2026 01:20
@dougqh
dougqh marked this pull request as ready for review September 2, 2026 01:28
@dougqh
dougqh requested a review from a team as a code owner September 2, 2026 01:28
@dougqh
dougqh requested review from bric3 and removed request for a team September 2, 2026 01:28
@datadog-datadog-prod-us1-2

This comment has been minimized.

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

Copy link
Copy Markdown
Contributor

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 guards prevent both null dereferences. They keep the existing behavior for non-null database types.

Was this helpful? React 👍 or 👎

Open Bits AI session

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

@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 23:49:56 UTC ℹ️ Start processing command /merge


2026-09-02 23:50:01 UTC ℹ️ MergeQueue: pull request added to the queue

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


2026-09-03 00:05:00 UTC ❌ MergeQueue: The build pipeline contains failing jobs for this merge request

Build pipeline has failing jobs for 28d87a9:

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

dd-octo-sts Bot commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

/merge

@gh-worker-devflow-routing-ef8351

gh-worker-devflow-routing-ef8351 Bot commented Sep 10, 2026 •

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2026-09-10 12:42:48 UTC ℹ️ Start processing command /merge


2026-09-10 12:42:54 UTC ℹ️ MergeQueue: pull request added to the queue

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


2026-09-10 13:40:23 UTC ❌ MergeQueue: The build pipeline contains failing jobs for this merge request

Build pipeline has failing jobs for 3abda34:

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

dd-octo-sts Bot commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

/merge

@gh-worker-devflow-routing-ef8351

gh-worker-devflow-routing-ef8351 Bot commented Sep 10, 2026 •

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2026-09-10 17:37:16 UTC ℹ️ Start processing command /merge


2026-09-10 17:37:22 UTC ℹ️ MergeQueue: pull request added to the queue

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


2026-09-10 18:37:25 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 Sep 10, 2026
@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot merged commit 7c6ce51 into master Sep 10, 2026
602 checks passed
@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot deleted the dougqh/fix-database-client-decorator-npe branch September 10, 2026 18:37
@github-actions github-actions Bot added this to the 1.67.0 milestone Sep 10, 2026
amarziali pushed a commit that referenced this pull request Sep 14, 2026
#12371)

Fix NPE in DatabaseClientDecorator when JDBC connection has no db type

processDatabaseType/dbService dereferenced the NamingEntry returned by
CACHE.computeIfAbsent(dbType, NamingEntry::new) without checking for
null. FixedSizeCache.computeIfAbsent returns null for a null key
without invoking the producer, so a null dbType() (e.g. an
undetermined DBInfo.getType()) led to a NullPointerException in
tracing instrumentation instead of a graceful no-op.

Guard on dbType == null directly instead of inferring it from the
cache's return value, and add a test exercising both methods with a
null dbType.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

Merge branch 'master' into dougqh/fix-database-client-decorator-npe

Merge branch 'master' into dougqh/fix-database-client-decorator-npe

Merge branch 'master' into dougqh/fix-database-client-decorator-npe

Co-authored-by: devflow.devflow-routing-intake <devflow.devflow-routing-intake@kubernetes.us1.ddbuild.io>
@ValentinZakharov ValentinZakharov changed the title Fix NPE in DatabaseClientDecorator when JDBC connection has no db type Fix NPE in JDBC instrumentation when connection has no database type Oct 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp: database Database Monitoring 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