Skip to content

Fix DB2 JDBC URL parsing failure when :// is only in a property value (quick fix) - #12803

Open
dougqh wants to merge 3 commits into
masterfrom
dougqh/jdbc-url-parser-db2
Open

dougqh wants to merge 3 commits into
masterfrom
dougqh/jdbc-url-parser-db2

Conversation

@dougqh

@dougqh dougqh commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

What Does This Do

Stops JDBCConnectionUrlParser from throwing StringIndexOutOfBoundsException on DB2/AS400 URLs that have no // after the type and whose only :// is inside a ; property value, for example:

  • jdbc:as400:host;ssltruststore=file://x
  • jdbc:as400:host;libraries=a;secure=true;keystore=file:///x
  • jdbc:db2:mydb;x=http://y

MODIFIED_URL_LIKE took that :// as the host delimiter. The type then wasn't db2/as400, so the code went down the generic ; branch and cut urlPart1 at the earlier ;. That left it shorter than hostIndex + 3, and urlPart1.substring(hostIndex + 3) threw. Now, when the first ; comes before ://, the parser returns the builder unchanged. That's the same DBInfo the exception fallback in parse already produced (type and default port 50000, no host), just without the exception. URLs that parsed before still parse the same way.

Motivation

Error Tracking issue https://app.datadoghq.com/error-tracking/issue/ab130d54-aab1-11f0-80ae-da7ad0900002 ("Error parsing URL", ~3.3k errors/day, still alerting on 1.66):

java.lang.StringIndexOutOfBoundsException
  at java.lang.String.substring
  at JDBCConnectionUrlParser$2.doParse(JDBCConnectionUrlParser.java:109)   // MODIFIED_URL_LIKE
  at JDBCConnectionUrlParser$9.doParse(JDBCConnectionUrlParser.java:344)   // DB2

#11550 (1.64.0) fixed one cause, the lastIndexOf(':') landing inside ://. But the monitor kept firing on 1.66. I ran a wide set of DB2/AS400 URL forms through DB2.doParse on current code, and the form above was the only one that still threw.

Additional Notes

  • Stacked on Fix Oracle and jTDS JDBC URL parsing failures (quick fix) #12780, which reworks the same file.
  • Added regression rows to JDBCConnectionUrlParserDB2Test. The test calls DB2.doParse directly because extractDBInfo swallows exceptions. All 4 rows fail without the fix and pass with it.
  • Ran :dd-java-agent:agent-bootstrap:test --tests '*JDBCConnectionUrlParser*', :dd-java-agent:instrumentation:jdbc:test --tests JDBCConnectionUrlParserTest, spotlessJavaCheck and forbiddenApisMain. All passed.

🤖 Generated with Claude Code

@dougqh dougqh added type: bug fix Bug fix inst: jdbc JDBC instrumentation tag: ai generated Largely based on code generated by an AI or LLM labels Oct 8, 2026
@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 sarahchen6 and removed request for a team October 8, 2026 19:34
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-08T19:37:58.288416Z da7f3d0 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: da7f3d0fff

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@datadog-official

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.75 s 14.71 s [-0.5%; +1.0%] (no difference)
startup:insecure-bank:tracing:Agent 13.55 s 13.58 s [-0.9%; +0.4%] (no difference)
startup:petclinic:appsec:Agent 17.23 s 17.01 s [+0.4%; +2.2%] (maybe worse)
startup:petclinic:iast:Agent 17.03 s 16.95 s [-0.4%; +1.3%] (no difference)
startup:petclinic:profiling:Agent 16.60 s 16.97 s [-3.1%; -1.3%] (significantly better)
startup:petclinic:sca:Agent 17.11 s 17.05 s [-0.6%; +1.3%] (no difference)
startup:petclinic:tracing:Agent 16.15 s 16.20 s [-1.3%; +0.6%] (no difference)

Commit: 1b235fd7 · 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.

@datadog-official datadog-official 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.

Bits Code Review: FAIL

The guard avoids the exception but drops recognized URL properties that the previous fallback preserved, including the user consumed by JDBC span decoration.

Open Bits AI session

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

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

The codex/dd review looks worth addressing, but otherwise LGTM

Base automatically changed from dougqh/jdbc-url-parser-oracle-jtds to master October 9, 2026 21:02
@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot requested a review from a team as a code owner October 9, 2026 21:02
@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot requested review from ValentinZakharov and removed request for a team October 9, 2026 21:02

@datadog-official datadog-official 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.

Bits Code Review: FAIL

Previously accepted ports such as +1444 now fall back to vendor defaults, producing incorrect JDBC connection metadata. The inline replacement preserves that compatibility without changing the integer utility's digits-only contract.

Open Bits AI session

🤖 Bits Code Review · Commit f39cdd7

Comment on lines +947 to +958
private static Integer parsePort(final CharSequence s, final int start, final int end) {
final int port = parseNonNegativeInt(s, start, end - start);
return port >= 0 ? port : null;
}

/**
* @return the port, or {@code null} if {@code s} is null or not a valid port number
*/
private static Integer parsePort(final String s) {
final int port = parseNonNegativeInt(s);
return port >= 0 ? port : null;
}

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.

P2 Preserve leading-plus ports in both parsing overloads

Previously accepted leading-plus ports now produce incorrect connection metadata. For example, jdbc:sqlserver://ss.host:+1444;databaseName=db now records port 1433 instead of 1444; portNumber=+9999 also regresses. Both parsePort overloads must preserve optional leading-plus handling while keeping the integer utility's digits-only contract.

Suggested change
private static Integer parsePort(final CharSequence s, final int start, final int end) {
final int port = parseNonNegativeInt(s, start, end - start);
return port >= 0 ? port : null;
}
/**
* @return the port, or {@code null} if {@code s} is null or not a valid port number
*/
private static Integer parsePort(final String s) {
final int port = parseNonNegativeInt(s);
return port >= 0 ? port : null;
}
private static Integer parsePort(final CharSequence s, final int start, final int end) {
final int digitsStart =
s != null && start >= 0 && start < end && end <= s.length() && s.charAt(start) == '+'
? start + 1
: start;
final int port = parseNonNegativeInt(s, digitsStart, end - digitsStart);
return port >= 0 ? port : null;
}
/**
* @return the port, or {@code null} if {@code s} is null or not a valid port number
*/
private static Integer parsePort(final String s) {
return s == null ? null : parsePort(s, 0, s.length());
}

Was this helpful? React 👍 or 👎
🤖 Bits Code Review · Open Bits AI session

dougqh and others added 2 commits October 9, 2026 17:52
A DB2/AS400 URL without // after the type (e.g. jdbc:as400:host;keystore=file:///x)
whose only :// sits inside a ';' property value made MODIFIED_URL_LIKE take the
'://' as the host delimiter while cutting urlPart1 at the earlier ';', so
urlPart1.substring(hostIndex + 3) threw StringIndexOutOfBoundsException.
Return the builder unchanged in that case, which is the same DBInfo the
exception fallback produced, minus the exception.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The early return skipped splitQuery/populateStandardProperties, so properties
such as user or schema were lost. The old parser applied them before throwing
and parse() returned that builder from its catch block, so populate them
before returning.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dougqh
dougqh force-pushed the dougqh/jdbc-url-parser-db2 branch from f39cdd7 to 07713f9 Compare October 9, 2026 22:02
@dougqh
dougqh enabled auto-merge October 10, 2026 01:43

This branch has not been deployed

No deployments
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 type: bug fix Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants