Skip to content

Fix StringIndexOutOfBoundsException parsing JTDS JDBC URLs without a database segment - #12227

Open
dougqh wants to merge 8 commits into
masterfrom
dougqh/fix-jtds-jdbc-url-port-parsing
Open

Fix StringIndexOutOfBoundsException parsing JTDS JDBC URLs without a database segment#12227
dougqh wants to merge 8 commits into
masterfrom
dougqh/fix-jtds-jdbc-url-port-parsing

Conversation

@dougqh

@dougqh dougqh commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

What Does This Do

Fixes the port-substring end index in JDBCConnectionUrlParser.doParse() for JTDS URLs: instead of always using dbLoc (which is -1 when there's no trailing /database), it now falls back to paramLoc (when there are ;params but no db) or details.length() (bare host:port).

Motivation

A JTDS URL of the form jdbc:jtds:sqlserver://host:1433 (host:port with no trailing /database and no ;params) has dbLoc == -1, and details.substring(portLoc + 1, dbLoc) threw StringIndexOutOfBoundsException. Found while triaging a production stack trace showing this exception escaping DriverManager.getConnection up through JDBCDecorator.

Additional Notes

None.

Test plan

  • Added regression cases to JDBCConnectionUrlParserTest.groovy: jdbc:jtds:sqlserver://dbhostname.com:1433 and jdbc:jtds:sqlserver://dbhostname.com:1433;user=user;password=pw
  • ./gradlew :dd-java-agent:instrumentation:jdbc:test --tests JDBCConnectionUrlParserTest passes
  • Ran /techdebt — no issues found

🤖 Generated with Claude Code

…ase segment

JTDS.doParse() used dbLoc as the end index when extracting the port
number, but dbLoc is -1 when the URL has a host:port with no trailing
/database and no ;params (e.g. jdbc:jtds:sqlserver://host:1433),
causing String.substring to throw.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@dougqh dougqh added type: bug fix Bug fix tag: no release notes Changes to exclude from release notes inst: jdbc JDBC instrumentation tag: ai generated Largely based on code generated by an AI or LLM labels Aug 17, 2026
@datadog-prod-us1-6

This comment has been minimized.

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

dd-octo-sts Bot commented Aug 17, 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.95 s 13.96 s [-0.9%; +0.7%] (no difference)
startup:insecure-bank:tracing:Agent 12.97 s 13.00 s [-1.3%; +0.7%] (no difference)
startup:petclinic:appsec:Agent 17.04 s 16.89 s [+0.1%; +1.7%] (maybe worse)
startup:petclinic:iast:Agent 17.00 s 17.01 s [-0.8%; +0.6%] (no difference)
startup:petclinic:profiling:Agent 16.66 s 16.94 s [-2.8%; -0.5%] (maybe better)
startup:petclinic:sca:Agent 16.90 s 16.88 s [-1.0%; +1.3%] (no difference)
startup:petclinic:tracing:Agent 16.04 s 16.10 s [-1.3%; +0.6%] (no difference)

Commit: 23e3f348 · 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 marked this pull request as ready for review August 21, 2026 13:29
@dougqh
dougqh requested review from a team as code owners August 21, 2026 13:29
@dougqh
dougqh requested review from vandonr and removed request for a team August 21, 2026 13:29

@datadog-prod-us1-6 datadog-prod-us1-6 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 new port end index supports JTDS URLs with no database segment. It also keeps the existing database and parameter boundaries.

Was this helpful? React 👍 or 👎

Open Bits AI session

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

@dougqh
dougqh requested a review from a team as a code owner August 28, 2026 19:42
@dougqh
dougqh requested review from bric3 and removed request for a team August 28, 2026 19:42
@gh-worker-ownership-write-b05516
gh-worker-ownership-write-b05516 Bot removed the request for review from a team August 28, 2026 19:42

@datadog-prod-us1-6 datadog-prod-us1-6 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 new port end uses the parameter start or the URL end when no database path exists. This change prevents the exception and keeps database path parsing unchanged.

Was this helpful? React 👍 or 👎

Open Bits AI session

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

@bric3 bric3 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.

Approving, thanks for the fix, the new port boundary matches the official jTDS URL grammar

@dougqh
dougqh enabled auto-merge September 1, 2026 20:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

inst: jdbc JDBC instrumentation tag: ai generated Largely based on code generated by an AI or LLM tag: no release notes Changes to exclude from release notes type: bug fix Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants