Skip to content

Fix NPE in DatabaseClientDecorator when JDBC connection has no db type - #12371

Open
dougqh wants to merge 1 commit into
masterfrom
dougqh/fix-database-client-decorator-npe
Open

Fix NPE in DatabaseClientDecorator when JDBC connection has no db type#12371
dougqh wants to merge 1 commit 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.96 s 13.86 s [-0.2%; +1.5%] (no difference)
startup:insecure-bank:tracing:Agent 12.89 s 12.99 s [-1.7%; +0.1%] (no difference)
startup:petclinic:appsec:Agent 17.00 s 16.88 s [-0.2%; +1.5%] (no difference)
startup:petclinic:iast:Agent 16.94 s 16.91 s [-0.7%; +0.9%] (no difference)
startup:petclinic:profiling:Agent 16.62 s 16.78 s [-2.0%; +0.0%] (no difference)
startup:petclinic:sca:Agent 16.87 s 16.65 s [+0.4%; +2.3%] (maybe worse)
startup:petclinic:tracing:Agent 16.06 s 15.99 s [-0.6%; +1.4%] (no difference)

Commit: 0dd0abed · 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

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.

2 participants